/** * Returns the solution X of the linear system A*X = B. * The matrix A must be square and non singular. * Also, the matrices A and B must have the same number of rows. * @param b the right-hand-side matrix B. * @return the solution matrix X. */ public DMatrix solve(DMatrix b) { Check.argument(_m==_n,"A is square"); Check.argument(_m==b.getM(),"A and B have same number of rows"); Check.state(!_singular,"A is not singular"); int n = _n; int nrhs = b.getN(); double[] aa = _lu; int lda = _m; int[] ipiv = _ipiv; double[] ba = b.getPackedColumns(); int ldb = _m; LapackInfo li = new LapackInfo(); _lapack.dgetrs("N",n,nrhs,aa,lda,ipiv,ba,ldb,li); li.check("dgetrs"); return new DMatrix(_m,nrhs,ba); }