package com.imsl.test.example.math; import com.imsl.math.*; /** *
* Computes the LU factorization of a complex matrix.
* * TheComplex
data 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.
*
* @see Code
* @see Output
*/
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);
}
}