Example: LU Decomposition of a Complex Matrix

The Complex class is used to convert a real matrix to a Complex matrix. An LU decomposition of the matrix is performed and the determinant and condition number of the matrix are obtained.
import com.imsl.math.*;

public class ComplexEx1 {
    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);
        
        // Solve Ax = b
        Complex	x[] = clu.solve(b);
        System.out.println("The solution is:");
        System.out.println(" ");
        new PrintMatrix("x").print(x);
        
        // Find the condition number of A.
        double	condition = clu.condition(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.