// Newton's method through the search of inverse matrix public double[] Method() { Console.Out.Write("Метод Ньютона с поиском обратной матрицы :" + "\n"); sw.Start(); x.InitX(); iter = 0; numOfOperations = 0; while (true) { iter++; // initialize function F and Jacoby's matrix F1.InitializationF(x); for (int i = 0; i < size; i++) { F[0, i] = F1[i]; } norm = 0; J = new SquareMatrix(InitializationExtension.InitializationJ(x), size); // make LU decomposition J.LUDecomposition(); numOfOperations += J.numOfOperations; currentX = SquareMatrix.multiplyVec(J.reverseMatrix, F1, size); for (int i = 0; i < size; i++) { xk1[i] = x[i] - currentX[i]; //norm += (xk1[i] - x[i]) * (xk1[i] - x[i]); if (Math.Abs(xk1[i] - x[i]) > norm) { norm = Math.Abs(xk1[i] - x[i]); } x[i] = xk1[i]; numOfOperations += 5; } if (norm < eps) { break; } } sw.Stop(); Console.Out.Write("Количество итераций :" + iter + "\n"); Console.Out.Write("Число арифметических операций :" + numOfOperations + "\n"); Console.Out.Write("Затраченное время :" + sw.Elapsed + "\n"); return(xk1); }
// Method with transition to modified public double[] TransitionToModMeth() { Console.Out.Write("Переход от обычного метода Ньютона к модифицированному :" + "\n"); int step = 8; Console.WriteLine("Шаг k = " + step); x.InitX(); double[] xFix = new double[size]; xFix.InitX(); double[] x0 = new double[size]; x0.InitX(); iter = 0; numOfOperations = 0; sw.Start(); while (true) { iter++; norm = 0; F1.InitializationF(x); for (int i = 0; i < size; i++) { F[0, i] = F1[i]; } if (step > 0) { J = new SquareMatrix(InitializationExtension.InitializationJ(x), size); J.LUDecomposition(); numOfOperations += J.numOfOperations; for (int i = 0; i < size; i++) { xFix[i] = x[i]; } //J.Reverse(); currentX = SquareMatrix.multiplyVec(J.reverseMatrix, F1, size); step--; } else { if (step == 0) { J = new SquareMatrix(InitializationExtension.InitializationJ(xFix), size); J.LUDecomposition(); } numOfOperations += J.numOfOperations; //currentX = J.SolutionSystem(F); currentX = SquareMatrix.multiplyVec(J.reverseMatrix, F1, size); step--; } for (int i = 0; i < size; i++) { xk1[i] = x[i] - currentX[i]; if (Math.Abs(xk1[i] - x[i]) > norm) { norm = Math.Abs(xk1[i] - x[i]); } x[i] = xk1[i]; numOfOperations += 5; } if (norm < eps) { break; } } sw.Stop(); Console.Out.Write("Количество итераций :" + iter + "\n"); Console.Out.Write("Число арифметических операций :" + numOfOperations + "\n"); Console.Out.Write("Затраченное время :" + sw.Elapsed + "\n"); return(xk1); }