Beispiel #1
0
        // Function solves Ax = b for A as a lower triangular matrix
        public static Matrice SubsForth(Matrice A, Matrice b)
        {
            if (A.L == null) A.MakeLU();
            int n = A.rows;
            Matrice x = new Matrice(n, 1);

            for (int i = 0; i < n; i++)
            {
                x[i, 0] = b[i, 0];
                for (int j = 0; j < i; j++) x[i, 0] -= A[i, j] * x[j, 0];
                x[i, 0] = x[i, 0] / A[i, i];
            }
            return x;
        }
Beispiel #2
0
        // Function solves Ax = b for A as an upper triangular matrix
        public static Matrice SubsBack(Matrice A, Matrice b)
        {
            if (A.L == null) A.MakeLU();
            int n = A.rows;
            Matrice x = new Matrice(n, 1);

            for (int i = n - 1; i > -1; i--)
            {
                x[i, 0] = b[i, 0];
                for (int j = n - 1; j > i; j--) x[i, 0] -= A[i, j] * x[j, 0];
                x[i, 0] = x[i, 0] / A[i, i];
            }
            return x;
        }