using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { public static double[,] T = new double[,] { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 } }; static void Main(string[] args) { List y = new List(); for (int i = 0; i < T.GetLength(0); i++) { for (int j = 0; j < T.GetLength(1)-1; j++) { T[i, j] = DoubleDiff(T[i, j], ref i, ref j) + Math.Pow(F(T[i, j], ref i, ref j), 2) * Diff(T[i, j], ref i, ref j) + Math.Pow(F(T[i, j], ref i, ref j), 3) * (F(T[i, j], ref i, ref j) - T[i,j]); } } for (int i = 0; i < T.GetLength(0); i++) { for (int j = 0; j < T.GetLength(1); j++) { Console.Write(T[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); Gauss(T); /*Console.WriteLine(); for (int i = 0; i < T.Length - 1; i++) { Console.Write(i + 1 + " "); } Console.WriteLine(); for (int i = 0; i < T.Length - 1; i++) { Console.Write(y[i] + " "); } Console.WriteLine(); for (int i = 0; i < T.Length - 1; i++) { Console.Write(y_e[i] + " "); } Console.WriteLine(); for (int i = 0; i < y.Count; i++) { e.Add(y_e[i] - y[i]); Console.Write(e[i] + " "); }*/ } static double F(double x, ref int i, ref int j) { return 14 * Math.Pow(x, 3) * (x - T[i, j]); } static double Diff(double x, ref int i, ref int j) { if(j==0) { return (F(x + T[i, j + 1], ref i, ref j) - F(T[i, j], ref i, ref j)) / (2 * 1); } return (F(T[i,j+1], ref i, ref j) - F(T[i,j-1], ref i, ref j)) / (2 * 1); } static double DoubleDiff(double x, ref int i, ref int j) { if(j==0) { return (F(T[i, j + 1], ref i, ref j) - 2 * F(x, ref i, ref j) + F(T[i, j], ref i, ref j)) / Math.Pow(1, 2); } return (F(T[i, j + 1], ref i, ref j) - 2 * F(x, ref i, ref j) + F(T[i,j-1], ref i, ref j)) / Math.Pow(1, 2); } static void Gauss(double[,] M) { Console.WriteLine("Start:"); for (int i = 0; i < M.GetLength(0); i++) { for (int j = 0; j < M.GetLength(1); j++) { Console.Write("| " + Math.Round(M[i, j], 1) + " |"); } Console.WriteLine(); } // size int rowCount = M.GetLength(0); for (int col = 0; col + 1 < rowCount; col++) if (M[col, col] == 0) { // find non-zero coefficient int swapRow = col + 1; for (; swapRow < rowCount; swapRow++) if (M[swapRow, col] != 0) break; if (M[swapRow, col] != 0) { // swap it with the above double[] tmp = new double[rowCount + 1]; for (int i = 0; i < rowCount + 1; i++) { tmp[i] = M[swapRow, i]; M[swapRow, i] = M[col, i]; M[col, i] = tmp[i]; } } } // elimination for (int sourceRow = 0; sourceRow + 1 < rowCount; sourceRow++) { for (int destRow = sourceRow + 1; destRow < rowCount; destRow++) { double df = M[sourceRow, sourceRow]; double sf = M[destRow, sourceRow]; for (int i = 0; i < rowCount + 1; i++) M[destRow, i] = M[destRow, i] * df - M[sourceRow, i] * sf;//умножаем n-ые элементы n строки на 1 эл-т 1 строки и наоборот,а затем вычитаем } } for (int row = rowCount - 1; row >= 0; row--) { double f = M[row, row]; //divide in all rows on first number this row(сокращаем по возможности всю строку) for (int i = 0; i < rowCount + 1; i++) M[row, i] /= f; // substiling the value(подставляем значения x1,x2,x3....) for (int destRow = 0; destRow < row; destRow++) { M[destRow, rowCount] -= M[destRow, row] * M[row, rowCount]; M[destRow, row] = 0; } } Console.WriteLine("Result:"); for (int i = 0; i < M.GetLength(0); i++) { for (int j = 0; j < M.GetLength(1); j++) { Console.Write("| " + Math.Round(M[i, j], 1) + " |"); } Console.WriteLine(); } Console.WriteLine(); for (int i = 0; i < M.GetLength(0); i++) { Console.WriteLine("X[{0}]=" + Math.Round(M[i, rowCount], 1), i + 1); } } } }