Example: LU Decomposition of a Complex Matrix

The Complex structure is used to convert a real matrix to a Complex matrix. An LU decomposition of the matrix is performed. The reciprocal of the condition number of the Matrix is then computed and checked against machine precision to determine whether or not to issue a Warning about the results. A linear system is then solved using the factorization. The determinant of the input matrix is also computed.
using System;
using Imsl.Math;

public class ComplexLUEx1
{
   public static void  Main(String[] args)
   {
      double[,] ar = {{1, 3, 3},
                     {1, 3, 4}, 
                     {1, 4, 3}};
      double[] br = {12, 13, 14};
      
      Complex[,] a = new Complex[3,3];
      Complex[] b = new Complex[3];
      
      for (int i = 0; i < 3; i++)
      {
         b[i] = new Complex(br[i]);
         for (int j = 0; j < 3; j++)
         {
            a[i,j] = new Complex(ar[i,j]);
         }
      }
      
      // Compute the LU factorization of A
      ComplexLU clu = new ComplexLU(a);

      // Check the reciprocal of the condition number of A 
      //   against machine precision
      double   condition = clu.Condition(a);

      if(condition <= 2.220446049250313e-16){
         Console.Out.WriteLine("WARNING. The matrix is too ill-conditioned.");
         Console.Out.WriteLine("An estimate of the reciprocal of its L1 " +
                               "condition number is "+condition+".");
         Console.Out.WriteLine("Results based on this factorization may " +
                               "not be accurate.");
      }
      
      // Solve Ax = b
      Complex[] x = clu.Solve(b);
      Console.Out.WriteLine("The solution is:");
      Console.Out.WriteLine(" ");
      new PrintMatrix("x").Print(x);
      
      // Print the condition number of A.
      Console.Out.WriteLine("The condition number = " + condition);
      Console.Out.WriteLine();
      
      // Find the determinant of A.
      Complex determinant = clu.Determinant();
      Console.Out.WriteLine("The determinant = " + determinant);
   }
}

Output

The solution is:
 
  x
   0  
0  3  
1  2  
2  1  

The condition number = 0.0148867313915858

The determinant = -0.99999999999999978

Link to C# source.