IMPLEMENTATION
LU Decomposition
The LU Decomposition is a matrix decomposition which represents a matrix as the product of a lower
and upper triangular matrix. This decomposition is used in numerical analysis to solve systems of
linear equations and to find the inverse of a matrix.
Algorithms
If a Matrix A can be written as the product of two matrices
where L is the lower triangular and U is the upper triangular. It is
possible then to use this decomposition to solve the linear equations,
A . x = (L .U) . x = L . (U . x) = b
|
by first solving for the vecor y such that
and then solving
The advantage of decomposing one linear system into two succesive ones is that the solution of a triangular set of equations
can be easily obtained just by a forward or backward substitution.
Matrix Inverse
Using the above LU decomposition and substitution methods, computing the inverse of a matrix column by
column is straightforward.
Testing LU Decomposition Method
In order to test the method as defined above, a new TestLUDecomposition()
static method has been added and executed. Supporting code and methods are not shown.
A set of initial equations for the test has been defined for Matrix A and Vector b.
static void TestLUDecomposition();
{
ListBox1.Items.Clear();
ListBox2.Items.Clear();
LinearSystem ls = new LinearSystem();
MatrixR A = new MatrixR(new double[3, 3] { { t1, t2, t3 }, { t4, t5, t6 }, { t7, t8, t9 } });
VectorR b = new VectorR(new double[3] { t10, t11, t12 });
MatrixR AA = A.Clone();
MatrixR BB = A.Clone();
double d = ls.LUCrout(A, b);
MatrixR inv = ls.LUInverse(AA);
ListBox1.Items.Add("Inverse of A = " + inv.ToString());
ListBox1.Items.Add(" " + " ");
ListBox1.Items.Add("Solution of the equations = " + b.ToString());
ListBox2.Items.Add("Determinant of A = -1");
ListBox2.Items.Add(" " + " ");
ListBox2.Items.Add("Test Inverse: BB*Inverse = " + BB * inv);
}
|