/** * Constructs and returns the LU-decomposition of the given matrix. * * @param matrix * sparse matrix * @param order * ordering option (0 to 3); 0: natural ordering, 1: amd(A+A'), * 2: amd(S'*S), 3: amd(A'*A) * @return the LU-decomposition of the given matrix */ public SparseDoubleLUDecomposition lu(DoubleMatrix2D matrix, int order) { return new CSparseDoubleLUDecomposition(matrix, order, true); }
public double det() { if (!isNonsingular()) return 0; // avoid rounding errors int pivsign = 1; for (int i = 0; i < n; i++) { if (N.pinv[i] != i) { pivsign = -pivsign; } } if (U == null) { U = new SparseCCDoubleMatrix2D(N.U); if (rcMatrix) { U = ((SparseCCDoubleMatrix2D) U).getRowCompressed(); } } double det = pivsign; for (int j = 0; j < n; j++) { det *= U.getQuick(j, j); } return det; }
public double det() { if (!isNonsingular()) return 0; // avoid rounding errors int pivsign = 1; for (int i = 0; i < n; i++) { if (N.pinv[i] != i) { pivsign = -pivsign; } } if (U == null) { U = new SparseCCDoubleMatrix2D(N.U); if (rcMatrix) { U = ((SparseCCDoubleMatrix2D) U).getRowCompressed(); } } double det = pivsign; for (int j = 0; j < n; j++) { det *= U.getQuick(j, j); } return det; }
public void solve(DoubleMatrix1D b) { if (b.size() != n) { throw new IllegalArgumentException("b.size() != A.rows()"); } if (!isNonsingular()) { throw new IllegalArgumentException("A is singular"); } DoubleProperty.DEFAULT.checkDense(b); double[] y = new double[n]; double[] x; if (b.isView()) { x = (double[]) b.copy().elements(); } else { x = (double[]) b.elements(); } Dcs_ipvec.cs_ipvec(N.pinv, x, y, n); /* y = b(p) */ Dcs_lsolve.cs_lsolve(N.L, y); /* y = L\y */ Dcs_usolve.cs_usolve(N.U, y); /* y = U\y */ Dcs_ipvec.cs_ipvec(S.q, y, x, n); /* b(q) = x */ if (b.isView()) { b.assign(x); } } }
/** * Constructs and returns the LU-decomposition of the given matrix. * * @param matrix * sparse matrix * @param order * ordering option (0 to 3); 0: natural ordering, 1: amd(A+A'), * 2: amd(S'*S), 3: amd(A'*A) * @return the LU-decomposition of the given matrix */ public SparseDoubleLUDecomposition lu(DoubleMatrix2D matrix, int order) { return new CSparseDoubleLUDecomposition(matrix, order, true); }
public void solve(DoubleMatrix1D b) { if (b.size() != n) { throw new IllegalArgumentException("b.size() != A.rows()"); } if (!isNonsingular()) { throw new IllegalArgumentException("A is singular"); } DoubleProperty.DEFAULT.checkDense(b); double[] y = new double[n]; double[] x; if (b.isView()) { x = (double[]) b.copy().elements(); } else { x = (double[]) b.elements(); } Dcs_ipvec.cs_ipvec(N.pinv, x, y, n); /* y = b(p) */ Dcs_lsolve.cs_lsolve(N.L, y); /* y = L\y */ Dcs_usolve.cs_usolve(N.U, y); /* y = U\y */ Dcs_ipvec.cs_ipvec(S.q, y, x, n); /* b(q) = x */ if (b.isView()) { b.assign(x); } } }