Example: LU Factorization of a Matrix

The LU Factorization of a Matrix is performed. A linear system is then solved using the factorization. The inverse, determinant, and condition number of the input matrix are also computed.
using System;
using Imsl.Math;

public class LUEx1
{
	public static void  Main(String[] args)
	{
		double[,] a = {
            {1, 3, 3}, 
            {1, 3, 4},
            {1, 4, 3}
        };
		double[] b = new double[]{12, 13, 14};
		
		// Compute the LU factorization of A
		LU lu = new LU(a);
		
		// Solve Ax = b
		double[] x = lu.Solve(b);
		new PrintMatrix("x").Print(x);
		
		// Find the inverse of A.
		double[,] ainv = lu.Inverse();
		new PrintMatrix("ainv").Print(ainv);
		
		// Find the condition number of A.
		double condition = lu.Condition(a);
		Console.Out.WriteLine("condition number = " + condition);
		Console.Out.WriteLine();
		
		// Find the determinant of A.
		double determinant = lu.Determinant();
		Console.Out.WriteLine("determinant = " + determinant);
	}
}

Output

  x
   0  
0  3  
1  2  
2  1  

               ainv
   0             1            2   
0   7  -3                     -3  
1  -1   2.22044604925031E-16   1  
2  -1   1                      0  

condition number = 0.0151202749140893

determinant = -1

Link to C# source.