/** test solve */
public void testSolve() {
QRDecomposition decomposition =
new QRDecompositionImpl(MatrixUtils.createRealMatrix(testData3x3NonSingular));
DecompositionSolver solver = decomposition.getSolver();
RealMatrix b = MatrixUtils.createRealMatrix(new double[][] {
{ -102, 12250 }, { 544, 24500 }, { 167, -36750 }
});
RealMatrix xRef = MatrixUtils.createRealMatrix(new double[][] {
{ 1, 2515 }, { 2, 422 }, { -3, 898 }
});
// using RealMatrix
assertEquals(0, solver.solve(b).subtract(xRef).getNorm(), 2.0e-16 * xRef.getNorm());
// using double[]
for (int i = 0; i < b.getColumnDimension(); ++i) {
final double[] x = solver.solve(b.getColumn(i));
final double error = new ArrayRealVector(x).subtract(xRef.getColumnVector(i)).getNorm();
assertEquals(0, error, 3.0e-16 * xRef.getColumnVector(i).getNorm());
}
// using ArrayRealVector
for (int i = 0; i < b.getColumnDimension(); ++i) {
final RealVector x = solver.solve(b.getColumnVector(i));
final double error = x.subtract(xRef.getColumnVector(i)).getNorm();
assertEquals(0, error, 3.0e-16 * xRef.getColumnVector(i).getNorm());
}
// using RealVector with an alternate implementation
for (int i = 0; i < b.getColumnDimension(); ++i) {
ArrayRealVectorTest.RealVectorTestImpl v =
new ArrayRealVectorTest.RealVectorTestImpl(b.getColumn(i));
final RealVector x = solver.solve(v);
final double error = x.subtract(xRef.getColumnVector(i)).getNorm();
assertEquals(0, error, 3.0e-16 * xRef.getColumnVector(i).getNorm());
}
}