package com.imsl.test.example.math; import com.imsl.math.*; /** *
* Performs the QR factorization of a matrix.
* * The QR factorization of a matrix is performed. A linear system is then solved * using the factorization. The rank of the input matrix is also computed. * * @see Code * @see Output * */ public class QREx1 { public static void main(String args[]) throws SingularMatrixException { double a[][] = { {1, 2, 4}, {1, 4, 16}, {1, 6, 36}, {1, 8, 64} }; double b[] = {4.999, 9.001, 12.999, 17.001}; // Compute the QR factorization of A QR qr = new QR(a); // Solve Ax = b double x[] = qr.solve(b); new PrintMatrix("x").print(x); // Print Q and R. new PrintMatrix("Q").print(qr.getQ()); new PrintMatrix("R").print(qr.getR()); // Find the rank of A. int rank = qr.getRank(); System.out.println("rank = " + rank); } }