Details
Description
QR and RRQR (rankrevealing) algorithms fail to find a leastsquares solution in some cases.
The following code:
final RealMatrix A = new BlockRealMatrix(3, 3);
A.setEntry(0, 0, 1);
A.setEntry(0, 1, 6);
A.setEntry(0, 2, 4);
A.setEntry(1, 0, 2);
A.setEntry(1, 1, 4);
A.setEntry(1, 2, 1);
A.setEntry(2, 0, 1);
A.setEntry(2, 1, 2);
A.setEntry(2, 2, 5);
final RealVector b = new ArrayRealVector(new double[]
);
final QRDecomposition qrDecomposition = new QRDecomposition(A);
final RRQRDecomposition rrqrDecomposition = new RRQRDecomposition(A);
final SingularValueDecomposition svd = new SingularValueDecomposition(A);
final RealVector xQR = qrDecomposition.getSolver().solve(b);
System.out.printf("QR solution: %s\n", xQR.toString());
final RealVector xRRQR = rrqrDecomposition.getSolver().solve(b);
System.out.printf("RRSQ solution: %s\n", xRRQR.toString());
final RealVector xSVD = svd.getSolver().solve(b);
System.out.printf("SVD solution: %s\n", xSVD.toString());
produces
QR solution: {3,575,212,378,628,897; 1,462,586,882,166,368; 1,300,077,228,592,326.5}
RRSQ solution:
SVD solution:
{0.5050344462; 1.0206677266; 0.2405935347}Showing that QR and RRQR algorithms fail to find the leastsquares solution. This can also be verified by calculating the dot product between columns of A and A*x  b:
// x = xQR, xRRQR or xSVD
final RealVector r = A.operate.subtract(b);
for (int i = 0; i < x.getDimension(); ++i)
Only SVD method passes this test with decent tolerance (1E14 or so).
Activity
Transition  Time In Source Status  Execution Times  Last Executer  Last Execution Date  


1d 23h 36m  1  Luc Maisonobe  23/Feb/14 11:15  

85d 3h 57m  1  Luc Maisonobe  19/May/14 15:13 
Status  Resolved [ 5 ]  Closed [ 6 ] 
Status  Open [ 1 ]  Resolved [ 5 ] 
Fix Version/s  3.3 [ 12324600 ]  
Resolution  Fixed [ 1 ] 
Field  Original Value  New Value 

Attachment  math1101bug.java [ 12630290 ] 
Closing all resolved issue now available in released 3.3 version.