Esempio n. 1
0
        // Function solves Ax = b for A as a lower triangular matrix
        public static Matrix4 SubsForth(Matrix4 A, Matrix4 b)
        {
            if (A.L == null) A.MakeLU();
            int n = A.rows;
            Matrix4 x = new Matrix4(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;
        }
Esempio n. 2
0
        // Function solves Ax = b for A as an upper triangular matrix
        public static Matrix4 SubsBack(Matrix4 A, Matrix4 b)
        {
            if (A.L == null) A.MakeLU();
            int n = A.rows;
            Matrix4 x = new Matrix4(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;
        }