package com.imsl.test.example.math; import com.imsl.math.*; /** *

* Performs the LU factorization of a matrix. *

* * The LU Factorization of a 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 inverse and * determinant of the input matrix are also computed. * * @see Code * @see Output */ public class LUEx1 { public static void main(String args[]) throws SingularMatrixException { double a[][] = { {1, 3, 3}, {1, 3, 4}, {1, 4, 3} }; double b[] = {12, 13, 14}; // Compute the LU factorization of A LU lu = new LU(a); // Check the reciprocal of the condition number of // A against machine precision double condition = lu.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 double x[] = lu.solve(b); new PrintMatrix("x").print(x); // Find the inverse of A. double ainv[][] = lu.inverse(); new PrintMatrix("ainv").print(ainv); // Print the condition number of A. System.out.println("condition number = " + condition); System.out.println(); // Find the determinant of A. double determinant = lu.determinant(); System.out.println("determinant = " + determinant); } }