public static void Rotation() { List <ArmihoLine> Output = new List <ArmihoLine>(); for (int i = 0; i <= 20; i++) { epsila = i * 0.05; var line = new ArmihoLine(); line.Iteration = epsila.ToString(); var min = ArmihoMovedown(0, 0); var c = min.Count(); line.Lambda = c.ToString(); Output.Add(line); } string filename = "Rosenbrok_armiho_iterations"; using (StreamWriter writer = new StreamWriter(filename + ".csv")) { using (CsvWriter csvWriter = new CsvWriter(writer, System.Globalization.CultureInfo.CurrentCulture)) { csvWriter.Configuration.Delimiter = ";"; csvWriter.WriteRecords(Output); } } }
public static List <Tuple <double, double> > ArmihoMovedown(double x, double y) { int iteration = 0; List <ArmihoLine> Output = new List <ArmihoLine>(); ArmihoLine header = new ArmihoLine(); header.Lambda = "Rosenbrok"; Output.Add(header); List <Tuple <double, double> > Allpoints = new List <Tuple <double, double> >(); Allpoints.Add(new Tuple <double, double>(x, y)); double norm = 1; Xtemp = Allpoints[iteration]; Gradtemp = AntiGradient(Xtemp.Item1, Xtemp.Item2); ArmihoLine firstline = new ArmihoLine(); firstline.Iteration = iteration.ToString(); firstline.X1 = x.ToString(); firstline.X2 = y.ToString(); firstline.F_x = Function(x, y).ToString(); //firstline.dF_dX1 = Gradtemp.Item1.ToString(); //firstline.dF_dX2 = Gradtemp.Item2.ToString(); Output.Add(firstline); do { ArmihoLine line = new ArmihoLine(); var alfa = CalcAlfaArmiho(); Allpoints.Add(new Tuple <double, double>(Allpoints[iteration].Item1 + alfa * Gradtemp.Item1, Allpoints[iteration].Item2 + alfa * Gradtemp.Item2)); iteration++; //norm = Function(Allpoints[iteration].Item1, Allpoints[iteration].Item2) - Function(Allpoints[iteration-1].Item1, Allpoints[iteration - 1].Item2); 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]; Gradtemp = AntiGradient(Xtemp.Item1, Xtemp.Item2); line.Iteration = iteration.ToString(); line.Lambda = alfa.ToString(); //line.deltaX1 = (alfa * Gradtemp.Item1).ToString(); //line.deltaX2 = (alfa * Gradtemp.Item2).ToString(); line.X1 = Xtemp.Item1.ToString(); line.X2 = Xtemp.Item2.ToString(); line.F_x = Function(Xtemp.Item1, Xtemp.Item2).ToString(); //line.dF_dX1 = Gradtemp.Item1.ToString(); //line.dF_dX2 = Gradtemp.Item2.ToString(); //line.norm_X = norm.ToString(); Output.Add(line); } while (norm > delta); ArmihoLine downheader = new ArmihoLine(); downheader.Lambda = "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_ellips11"; 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); }