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.

import com.imsl.math.*;

public class ComplexLUEx1 {

    public static void main(String args[]) throws SingularMatrixException {
        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) {
            System.out.println("WARNING. The matrix is too ill-conditioned.");
            System.out.println("An estimate of the reciprocal of its L1 "
                    + "condition number is " + condition + ".");
            System.out.println("Results based on this factorization may "
                    + "not be accurate.");
        }

        // Solve Ax = b
        Complex x[] = clu.solve(b);
        System.out.println("The solution is:");
        System.out.println(" ");
        new PrintMatrix("x").print(x);

        // Print the condition number of A.
        System.out.println("The condition number = " + condition);
        System.out.println();

        // Find the determinant of A.
        Complex determinant = clu.determinant();
        System.out.println("The determinant = " + determinant);
    }
}

Output

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

The condition number = 0.014886731391585757

The determinant = -0.9999999999999998
Link to Java source.