private void NiutonoMetodas(Func <double, double> funkcija) { double x0 = 5; double abs; int i = 1; double prec = 0.0001; int kvietimuSkaicius = 0; double yy1 = Differentiate.Derivative(funkcija, x0, 1); double yy2 = Differentiate.Derivative(funkcija, x0, 2); kvietimuSkaicius += 2; double x1 = x0 - (yy1 / yy2); abs = Math.Abs(x1 - x0); Console.WriteLine("\n|| Niutono metodas ||\n"); chartNewton.Series["x0"].Points.AddXY(i, x0); chartNewton.Series["x1"].Points.AddXY(i, x1); string[] row = { i.ToString(), x0.ToString(), x1.ToString(), (x0 - x1).ToString("0." + new string('#', 339)) }; dataGridViewNewton.Rows.Add(row); while (!(abs < prec)) { yy1 = Differentiate.Derivative(funkcija, x1, 1); yy2 = Differentiate.Derivative(funkcija, x1, 2); kvietimuSkaicius += 2; i++; x0 = x1 - (yy1 / yy2); var temp = x1; x1 = x0; x0 = temp; abs = Math.Abs(x1 - x0); chartNewton.Series["x0"].Points.AddXY(i, x0); chartNewton.Series["x1"].Points.AddXY(i, x1); row = new string[] { i.ToString(), x0.ToString(), x1.ToString(), (x0 - x1).ToString("0." + new string('#', 339)) }; dataGridViewNewton.Rows.Add(row); } kvietimuSkaicius += 1; Console.WriteLine("Prireike {0} iteraciju bei {1} funkcijos kvietimu", i, kvietimuSkaicius); Console.WriteLine("Atsakymas yra X = {0} Y = {1}", x1, funkcija(x1)); }
protected double Derivative(double inputX, int order) { return(Differentiate.Derivative(CalculateByPoint, inputX, order)); }