void CalculGaussCoefs(int N, out double[] LegendreRoots, out double[] GaussCoefs) { LegendrePolynom Polynom = new LegendrePolynom(N, 1e-9); double[,] Matrix = new double[N, N + 1]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == 0) { Matrix[i, j] = 1; } else { Matrix[i, j] = Math.Pow(Polynom.Roots[j], i); } } if (i % 2 == 0) { Matrix[i, N] = 2.0 / (i + 1); } else { Matrix[i, N] = 0; } } GaussCoefs = SLE.GaussSolve(Matrix, N); LegendreRoots = Polynom.Roots; }
public List <double> SeekIterations(SLE m, List <double> answers, int n) { for (int i = 0; i < n; i++) { logger.Log(answers); answers = Iterate(m, answers); } return(answers); }
public List <double> Seek(SLE m, List <double> answers) { while (!Stop(m, answers)) { logger.Log(answers); answers = Iterate(m, answers); } return(answers); }
protected bool Stop(SLE m, List <double> answers) { var newAnswers = new List <double>(Iterate(m, answers)); for (int i = 0; i < m.Right.Count; i++) { if (Math.Abs(answers[i] - newAnswers[i]) >= precision) { return(false); } } return(true); }
static void Input() { Console.WriteLine("Введите количество неизвестных"); int n = int.Parse(Console.ReadLine()); Console.WriteLine("Введите коэффиценты матрицы системы"); double[,] matrix = new double[n, n]; for (int i = 0; i < n; i++) { string[] str = Console.ReadLine().Split(); for (int j = 0; j < n; j++) { matrix[i, j] = Convert.ToDouble(str[j]); } } Console.WriteLine("Введите вектор свободных коэффицентов"); double[] value = new double[n]; string[] temp = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { value[i] = double.Parse(temp[i]); } SLE system = new SLE(new Matrix(matrix), new Vector(value)); Console.WriteLine(); Console.WriteLine("Метод Крамера"); system.Kramer(); Console.WriteLine("Метод обратной матрицы"); system.InvertibleMatrix(); Console.WriteLine("Метод Гаусса"); system.Gauss(); Console.WriteLine("Метод прогонки"); system.TridiagonalMatrixAlgorithm(); Console.WriteLine("Метод квадратных корней"); system.CholeskyDecomposition(); Console.WriteLine("Метод простых итераций"); system.Itera(0.001); Console.WriteLine("Метод Зейделя"); system.Seidel(0.001); }
static double Gauss(double p) { double Result = 0; double[,] Matrix = new double[N, N + 1]; LegendrePolynom.GetValueAt(0); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == 0) { Matrix[i, j] = 1; } else { Matrix[i, j] = Math.Pow(LegendrePolynom.Roots[j], i); } } if (i % 2 == 0) { Matrix[i, N] = 2.0 / (i + 1); } else { Matrix[i, N] = 0; } } double[] ResultColumn = SLE.GaussSolve(Matrix, N); for (int i = 0; i < N; i++) { double z = 0.5 + LegendreCoefs[i] * 0.5; Result += ResultColumn[i] * Integrand(p, z); } Result *= 0.5; return(Result); }
abstract public List <double> Iterate(SLE m, List <double> answers);