Exemple #1
0
        public static void Rotation()
        {
            List <Double_dim_line> Output = new List <Double_dim_line>();

            int[] multiplier = new int[7];
            multiplier[0] = 1;
            multiplier[1] = 5;
            multiplier[2] = 10;
            multiplier[3] = 20;
            multiplier[4] = 50;
            multiplier[5] = 70;
            multiplier[6] = 100;
            for (int i = 0; i <= 8; i++)
            {
                //B = multiplier[i];
                FI = i * Math.PI / 4;
                var line = new Double_dim_line();
                //double dist = Math.Sqrt(Math.Pow(i * 0.5, 2) * 2);
                line.Iteration = i.ToString();
                var min = FastestMovedown(4, 5);
                var c   = min.Count();
                line.deltaX1 = c.ToString();
                Output.Add(line);
            }
            string filename = "Neuton_rotation1";

            using (StreamWriter writer = new StreamWriter(filename + ".csv"))
            {
                using (CsvWriter csvWriter = new CsvWriter(writer, System.Globalization.CultureInfo.CurrentCulture))
                {
                    csvWriter.Configuration.Delimiter = ";";
                    csvWriter.WriteRecords(Output);
                }
            }
        }
Exemple #2
0
        public static List <Tuple <double, double> > FastestMovedown(double x, double y)
        {
            List <Double_dim_line> Output = new List <Double_dim_line>();
            Double_dim_line        header = new Double_dim_line();

            header.Iteration = "F(x,y) = x^2 + 2y^2 -4x + 2y";
            Output.Add(header);
            List <Tuple <double, double> > Allpoints = new List <Tuple <double, double> >();

            Allpoints.Add(new Tuple <double, double>(x, y));
            int    iteration = 0;
            double norm      = 1;

            Xtemp       = Allpoints[iteration];
            MovedownWay = SecondTierWay(Xtemp.Item1, Xtemp.Item2);
            Double_dim_line firstline = new Double_dim_line();

            firstline.Iteration = iteration.ToString();
            firstline.X1        = x.ToString();
            firstline.X2        = y.ToString();
            firstline.F_x       = Function(x, y).ToString();
            firstline.dF_dX1    = MovedownWay.Item1.ToString();
            firstline.dF_dX2    = MovedownWay.Item2.ToString();
            Output.Add(firstline);
            do
            {
                Double_dim_line line = new Double_dim_line();

                double firstboarder = 0;
                double alfatemp     = 0.0001;
                int    direction    = 1;
                if (F(firstboarder) > F(firstboarder + alfatemp))
                {
                    direction = 1;
                }
                else
                {
                    direction = -1;
                }
                while (F(firstboarder) > F(firstboarder + alfatemp * direction))
                {
                    alfatemp *= 2;
                }
                double secondboarder = firstboarder + alfatemp * direction;
                if (firstboarder > secondboarder)
                {
                    var bubble = firstboarder;
                    firstboarder  = secondboarder;
                    secondboarder = bubble;
                }
                var alfa = 1;// GoldenCut_Calculation(firstboarder, secondboarder);
                Allpoints.Add(new Tuple <double, double>(Allpoints[iteration].Item1 + alfa * MovedownWay.Item1, Allpoints[iteration].Item2 + alfa * MovedownWay.Item2));
                iteration++;
                norm = Math.Sqrt(Math.Pow(Allpoints[iteration].Item1 - Allpoints[iteration - 1].Item1, 2)
                                 + Math.Pow(Allpoints[iteration].Item2 - Allpoints[iteration - 1].Item2, 2));
                Xtemp          = Allpoints[iteration];
                MovedownWay    = SecondTierWay(Xtemp.Item1, Xtemp.Item2);
                line.Iteration = iteration.ToString();
                //line.Lambda = alfa.ToString();
                line.deltaX1 = (alfa * MovedownWay.Item1).ToString();
                line.deltaX2 = (alfa * MovedownWay.Item2).ToString();
                line.X1      = Xtemp.Item1.ToString();
                line.X2      = Xtemp.Item2.ToString();
                line.F_x     = Function(Xtemp.Item1, Xtemp.Item2).ToString();
                line.dF_dX1  = MovedownWay.Item1.ToString();
                line.dF_dX2  = MovedownWay.Item2.ToString();
                line.norm_X  = norm.ToString();
                Output.Add(line);
            } while (norm > delta);
            Double_dim_line downheader = new Double_dim_line();

            downheader.deltaX2 = "Extremum";
            downheader.X1      = Xtemp.Item1.ToString();
            downheader.X2      = Xtemp.Item2.ToString();
            downheader.F_x     = Function(Xtemp.Item1, Xtemp.Item2).ToString();
            Output.Add(downheader);
            string filename = "Prot_9_11_20_11";

            using (StreamWriter writer = new StreamWriter(filename + ".csv"))
            {
                using (CsvWriter csvWriter = new CsvWriter(writer, System.Globalization.CultureInfo.CurrentCulture))
                {
                    csvWriter.Configuration.Delimiter = ";";
                    csvWriter.WriteRecords(Output);
                }
            }
            return(Allpoints);
        }