@Test(expected = SingularMatrixException.class) public void solveMtxSingularMatrix() throws Exception { new LUDecomposition(new DenseMatrix(testMatrix.rowSize(), testMatrix.rowSize())) .solve(new DenseMatrix(testMatrix.rowSize(), testMatrix.rowSize())); }
public Vector solve(Vector b) { final int m = pivot.size(); if (b.size() != m) throw new CardinalityException(b.size(), m); if (singular) throw new SingularMatrixException(); final double[] bp = new double[m]; for (int row = 0; row < m; row++) bp[row] = b.get((int)pivot.get(row)); for (int col = 0; col < m; col++) { final double bpCol = bp[col]; for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col); } for (int col = m - 1; col >= 0; col--) { bp[col] /= lu.get(col, col); final double bpCol = bp[col]; for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col); } return b.like(m).assign(bp); }
LUDecomposition implements AutoCloseable { public Vector solve(Vector b) { final int m = pivot.size(); if (b.size() != m) throw new CardinalityException(b.size(), m); if (singular) throw new SingularMatrixException(); final double[] bp = new double[m]; for (int row = 0; row < m; row++) bp[row] = b.get((int)pivot.get(row)); for (int col = 0; col < m; col++) { final double bpCol = bp[col]; for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col); } for (int col = m - 1; col >= 0; col--) { bp[col] /= lu.get(col, col); final double bpCol = bp[col]; for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col); } return b.like(m).assign(bp); } }
LUDecomposition implements AutoCloseable { public Vector solve(Vector b) { final int m = pivot.size(); if (b.size() != m) throw new CardinalityException(b.size(), m); if (singular) throw new SingularMatrixException(); final double[] bp = new double[m]; for (int row = 0; row < m; row++) bp[row] = b.get((int)pivot.get(row)); for (int col = 0; col < m; col++) { final double bpCol = bp[col]; for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col); } for (int col = m - 1; col >= 0; col--) { bp[col] /= lu.get(col, col); final double bpCol = bp[col]; for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col); } return b.like(m).assign(bp); } LUDecomposition(Matrix matrix);  LUDecomposition(Matrix matrix, double singularityThreshold); }
LUDecomposition implements AutoCloseable { public Vector solve(Vector b) { final int m = pivot.size(); if (b.size() != m) throw new CardinalityException(b.size(), m); if (singular) throw new SingularMatrixException(); final double[] bp = new double[m]; for (int row = 0; row < m; row++) bp[row] = b.get((int)pivot.get(row)); for (int col = 0; col < m; col++) { final double bpCol = bp[col]; for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col); } for (int col = m - 1; col >= 0; col--) { bp[col] /= lu.get(col, col); final double bpCol = bp[col]; for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col); } return b.like(m).assign(bp); } LUDecomposition(Matrix matrix);  LUDecomposition(Matrix matrix, double singularityThreshold); @Override void close(); Matrix getL(); Matrix getU(); Matrix getP(); Vector getPivot(); double determinant(); Vector solve(Vector b); Matrix solve(Matrix b); }
LUDecomposition implements AutoCloseable { public Vector solve(Vector b) { final int m = pivot.size(); if (b.size() != m) throw new CardinalityException(b.size(), m); if (singular) throw new SingularMatrixException(); final double[] bp = new double[m]; for (int row = 0; row < m; row++) bp[row] = b.get((int)pivot.get(row)); for (int col = 0; col < m; col++) { final double bpCol = bp[col]; for (int i = col + 1; i < m; i++) bp[i] -= bpCol * lu.get(i, col); } for (int col = m - 1; col >= 0; col--) { bp[col] /= lu.get(col, col); final double bpCol = bp[col]; for (int i = 0; i < col; i++) bp[i] -= bpCol * lu.get(i, col); } return b.like(m).assign(bp); } LUDecomposition(Matrix matrix);  LUDecomposition(Matrix matrix, double singularityThreshold); @Override void close(); Matrix getL(); Matrix getU(); Matrix getP(); Vector getPivot(); double determinant(); Vector solve(Vector b); Matrix solve(Matrix b);  }