It is necessary to solve SLAU by iterative method. All methods are already available, you just need to apply them correctly in the program file
Console.WriteLine("Есть матрица А"); double[,] A = { { 2, 1 }, { 1, -2 } }; Matrix.dispMartix(A); Console.WriteLine("и eё вектор решений"); double[] B = { 3, 1 }; Matrix.dispVec(B); Console.WriteLine(); double[] C; C = SLAU.solveByInv(A,B); Matrix.dispVec(C); double tor=10; double[] C1; C1 = SLAU.iteration(A,B,tor); Matrix.dispVec(C1); Methods themselves
public static double[] solveByInv(double[,] A, double[] b) { double[] res = new double[b.GetLength(0)]; res = Matrix.multMatToVec(Matrix.invertMatrix(A), b); return res; } public static double findMaxDiff(double[] V1, double[] V2) { double[] diff = Matrix.addVecToVec(V1, Matrix.multVecToNumb(V2, -1)); double res = Math.Abs(diff[0]); for (int i = 0; i < diff.GetLength(0) - 1; i++) { if (Math.Abs(diff[i + 1]) >= diff[i]) { res = Math.Abs(diff[i + 1]); } } return res; } public static double[] iteration(double[,] c, double[] b, double eps) { double[] result = new double[c.GetLength(0)]; double[] previousRes = new double[result.GetLength(0)]; double normC = 0; for (int row = 0; row < c.GetLength(0); row++) { for (int col = 0; col < c.GetLength(1); col++) { normC += Math.Pow(c[row, col], 2); } } normC = Math.Sqrt(normC); if (normC > 1) { Console.WriteLine("Есть решение"); } else { Console.WriteLine("Решений нет"); } for (int i = 0; i < previousRes.GetLength(0); i++) { previousRes[i] = 0; } double max = -1; // итерац. проц Xi+1=Cxi+b do { max = -1; result = Matrix.addVecToVec(Matrix.multMatToVec(c, previousRes), b); max = SLAU.findMaxDiff(result, previousRes); for (int i = 0; i < result.GetLength(0); i++) { previousRes[i] = result[i]; } } while (max > eps); return result; } How to apply them correctly? Also already written a bunch of other methods for working with matrices.