diff --git a/src/site/xdoc/userguide/linear.xml b/src/site/xdoc/userguide/linear.xml index 7319885cd..69be4642e 100644 --- a/src/site/xdoc/userguide/linear.xml +++ b/src/site/xdoc/userguide/linear.xml @@ -42,9 +42,7 @@ @@ -67,8 +65,9 @@ RealMatrix p = m.multiply(n); System.out.println(p.getRowDimension()); // 2 System.out.println(p.getColumnDimension()); // 2 -// Invert p -RealMatrix pInverse = new LUDecompositionImpl(p).inverse(); +// Invert p, using LU decomposition +DecompositionSolver solver = new DecompositionSolver(p); +RealMatrix pInverse = solver.inverse(solver.luDecompose());

@@ -94,7 +93,7 @@ RealMatrix pInverse = new LUDecompositionImpl(p).inverse();

- The solve() methods of the DecompositionSolver interface + The solve() methods of the DecompositionSolver class support solving linear systems of equations of the form AX=B, either in linear sense or in least square sense. In each case, the RealMatrix represents the coefficient matrix of the system. For example, to solve the linear system @@ -103,19 +102,20 @@ RealMatrix pInverse = new LUDecompositionImpl(p).inverse(); -x + 7y + 6x = -2 4x - 3y - 5z = 1 - Start by creating a RealMatrix to store the coefficients matrix A + Start by creating a RealMatrix to store the coefficients matrix A and provide it + to a solver RealMatrix coefficients = new RealMatrixImpl(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } }, false); +DecompositionSolver solver = new DecompositionSolver(coefficients); Next create a RealVector array to represent the constant - vector B and use solve(RealVector) from one of the implementations - of the DecompositionSolver interface, for example - LUDecompositionImpl to solve the system + vector B, select one of the decomposition algorithms (LU, QR ...) and use + solve(vector, decomposition) to solve the system RealVector constants = new RealVectorImpl(new double[] { 1, -2, 1 }, false); -RealVector solution = new LUDecompositionImpl(coefficients).solve(constants); +RealVector solution = solver.solve(constants, solver.luDecomposition()); The solution vector will contain values for x (solution.getEntry(0)), y (solution.getEntry(1)), @@ -146,7 +146,7 @@ RealVector solution = new LUDecompositionImpl(coefficients).solve(constants); It is possible to solve multiple systems with the same coefficient matrix in one method call. To do this, create a matrix whose column vectors correspond to the constant vectors for the systems to be solved and use - solve(RealMatrix), which returns a matrix with column + solve(matrix, decomposition), which returns a matrix with column vectors representing the solutions.