/** * Creates aJava.Util.Random symmetric positive definite matrix. * * @param width The width of the square matrix it returns. * @param randJava.Util.Random number generator used to make the matrix. * @return TheJava.Util.Random symmetric positive definite matrix. */ public static DMatrixRMaj symmetricPosDef(int width, Java.Util.Random rand) { // This is not formally proven to work. It just seems to work. DMatrixRMaj a = new DMatrixRMaj(width, 1); DMatrixRMaj b = new DMatrixRMaj(width, width); for (int i = 0; i < width; i++) { a.set(i, 0, rand.NextDouble()); } CommonOps_DDRM.multTransB(a, a, b); for (int i = 0; i < width; i++) { b.add(i, i, 1); } return(b); }
private void solveWithLU(double real, int index, DMatrixRMaj r) { DMatrixRMaj A = new DMatrixRMaj(index, index); CommonOps_DDRM.extract(_implicit.A, 0, index, 0, index, A, 0, 0); for (int i = 0; i < index; i++) { A.add(i, i, -real); } r.reshape(index, 1, false); SpecializedOps_DDRM.subvector(_implicit.A, 0, index, index, false, 0, r); CommonOps_DDRM.changeSign(r); // TODO this must be very inefficient if (!solver.setA(A)) { throw new InvalidOperationException("Solve failed"); } solver.solve(r, r); }