public static void invert(LinearSolverDense <ZMatrixRMaj> solver, ZMatrixRMaj A, ZMatrixRMaj A_inv) { if (A.numRows != A_inv.numRows || A.numCols != A_inv.numCols) { throw new ArgumentException("A and A_inv must have the same dimensions"); } CommonOps_ZDRM.setIdentity(A_inv); solver.solve(A_inv, A_inv); }
/** * <p> * To decompose the matrix 'A' it must have full rank. 'A' is a 'm' by 'n' matrix. * It requires about 2n*m<sup>2</sup>-2m<sup>2</sup>/3 flops. * </p> * * <p> * The matrix provided here can be of different * dimension than the one specified in the constructor. It just has to be smaller than or equal * to it. * </p> */ //@Override public bool decompose(ZMatrixRMaj A) { setExpectedMaxSize(A.numRows, A.numCols); CommonOps_ZDRM.transpose(A, QR); error = false; for (int j = 0; j < minLength; j++) { householder(j); updateA(j); } return(!error); }
public static ZMatrixRMaj checkIdentity(ZMatrixRMaj A, int numRows, int numCols) { if (A == null) { return(CommonOps_ZDRM.identity(numRows, numCols)); } else if (numRows != A.numRows || numCols != A.numCols) { throw new ArgumentException("Input is not " + numRows + " x " + numCols + " matrix"); } else { CommonOps_ZDRM.setIdentity(A); } return(A); }
public override /**/ double quality() { return(SpecializedOps_ZDRM.qualityTriangular(R)); } /** * Solves for X using the QR decomposition. * * @param B A matrix that is n by m. Not modified. * @param X An n by m matrix where the solution is written to. Modified. */ //@Override public override void solve(ZMatrixRMaj B, ZMatrixRMaj X) { if (X.numRows != numCols) { throw new ArgumentException("Unexpected dimensions for X"); } else if (B.numRows != numRows || B.numCols != X.numCols) { throw new ArgumentException("Unexpected dimensions for B"); } int BnumCols = B.numCols; Y.reshape(numRows, 1); Z.reshape(numRows, 1); // solve each column one by one for (int colB = 0; colB < BnumCols; colB++) { // make a copy of this column in the vector for (int i = 0; i < numRows; i++) { int indexB = B.getIndex(i, colB); Y.data[i * 2] = B.data[indexB]; Y.data[i * 2 + 1] = B.data[indexB + 1]; } // Solve Qa=b // a = Q'b CommonOps_ZDRM.mult(Qt, Y, Z); // solve for Rx = b using the standard upper triangular solver TriangularSolver_ZDRM.solveU(R.data, Z.data, numCols); // save the results for (int i = 0; i < numCols; i++) { X.set(i, colB, Z.data[i * 2], Z.data[i * 2 + 1]); } } }
/** * Performs QR decomposition on A * * @param A not modified. */ //@Override public override bool setA(ZMatrixRMaj A) { if (A.numRows > maxRows || A.numCols > maxCols) { setMaxSize(A.numRows, A.numCols); } _setA(A); if (!decomposer.decompose(A)) { return(false); } Q.reshape(numRows, numRows); R.reshape(numRows, numCols); decomposer.getQ(Q, false); decomposer.getR(R, false); CommonOps_ZDRM.transposeConjugate(Q, Qt); return(true); }
//@Override public void minus(ZMatrixRMaj A, ZMatrixRMaj B, ZMatrixRMaj output) { CommonOps_ZDRM.subtract(A, B, output); }
//@Override public void plus(ZMatrixRMaj A, ZMatrixRMaj B, ZMatrixRMaj output) { CommonOps_ZDRM.add(A, B, output); }
//@Override public void mult(ZMatrixRMaj A, ZMatrixRMaj B, ZMatrixRMaj output) { CommonOps_ZDRM.mult(A, B, output); }
//@Override public void transpose(ZMatrixRMaj input, ZMatrixRMaj output) { CommonOps_ZDRM.transpose(input, output); }