Пример #1
0
        public Gauss(int n, double[,] A)
        {
            this.n = n;
            this.A = A;
            E      = Constants.GetE();

            UserConsole.PrintNumber("Порядок системы, n", n);
            UserConsole.PrintMatrix("Матрица системы, A", A, n);
        }
Пример #2
0
        public void GaussInverse()
        {
            Inverse = new double[n, n];

            for (int i = 0; i < n; i++)
            {
                for (int j = n - 1; j >= 0; j--)
                {
                    Inverse[i, j] = E[i, j];
                    for (int k = j + 1; k < n; k++)
                    {
                        Inverse[i, j] = Inverse[i, j] - TriangM[j, k] * Inverse[i, k];
                    }

                    Inverse[i, j] = Inverse[i, j] / TriangM[j, j];
                }
            }

            Inverse = Calculator.TransposeMatrix(Inverse, n);
            UserConsole.PrintMatrix("Обратная матрица", Inverse, n);
        }
Пример #3
0
        public void Verification()
        {
            var calc = new double[n, n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    calc[i, j] = 0;
                    for (int k = 0; k < n; k++)
                    {
                        calc[i, j] += Inverse[i, k] * A[k, j];
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                calc[i, i] -= 1;
            }

            UserConsole.PrintMatrix("Матрица невязки", calc, n);
        }
Пример #4
0
        public void Triangle()
        {
            TriangM = Calculator.GetMatrixCopy(A, n);

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    double koef = TriangM[j, i] / TriangM[i, i];
                    for (int k = i; k < n; k++)
                    {
                        TriangM[j, k] = TriangM[j, k] - TriangM[i, k] * koef;
                    }

                    for (int k = 0; k < n; k++)
                    {
                        E[k, j] = E[k, j] - E[k, i] * koef;
                    }
                }
            }

            UserConsole.PrintMatrix("Треугольная матрица", TriangM, n);
        }