Wed 06 Dec 2017 12:01:44 AM UTC, original submission:
It looks like qr(A,'matrix') and qr(A,'vector') return the wrong result when the matrix is tall and skinny. For example,
> A=[-3.6 0 9.72;3.4 1.9 8.67;3.8 1.7 0;-1.6 4 0;-1.6 4 0];
> [Q R p] = qr(A,'vector')
Q =
0.74626 -0.49565 -0.14732
0.66565 0.55568 0.16516
0.00000 0.57352 0.27055
0.00000 -0.24148 0.66250
0.00000 -0.24148 0.66250
R =
13.02487 -0.42334 1.26473
0.00000 6.62577 0.09892
0.00000 0.00000 6.07377
p =
3 1 2
and
> A=[-3.6 0 9.72;3.4 1.9 8.67;3.8 1.7 0;-1.6 4 0;-1.6 4 0];
> [Q R p] = qr(A,'matrix')
Q =
0.74626 -0.49565 -0.14732
0.66565 0.55568 0.16516
0.00000 0.57352 0.27055
0.00000 -0.24148 0.66250
0.00000 -0.24148 0.66250
R =
13.02487 -0.42334 1.26473
0.00000 6.62577 0.09892
0.00000 0.00000 6.07377
p =
3 1 2
In both cases, the skinny factorization is given, which normally requires the argument 0 to be passed. In addition, when matrix a matrix permutation is requested, a vector permutation is given. Conversely, in MATLAB, we have:
>> A = [-3.6 0 9.72;3.4 1.9 8.67;3.8 1.7 0;-1.6 4 0;-1.6 4 0];
>> [Q R p] = qr(A,'vector')
Q =
-0.7463 0.4957 0.1473 -0.2964 -0.2964
-0.6656 -0.5557 -0.1652 0.3323 0.3323
0 -0.5735 -0.2706 -0.5468 -0.5468
0 0.2415 -0.6625 0.5373 -0.4627
0 0.2415 -0.6625 -0.4627 0.5373
R =
-13.0249 0.4233 -1.2647
0 -6.6258 -0.0989
0 0 -6.0738
0 0 0
0 0 0
p =
3 1 2
>> [Q R p] = qr(A,'matrix')
Q =
-0.7463 0.4957 0.1473 -0.2964 -0.2964
-0.6656 -0.5557 -0.1652 0.3323 0.3323
0 -0.5735 -0.2706 -0.5468 -0.5468
0 0.2415 -0.6625 0.5373 -0.4627
0 0.2415 -0.6625 -0.4627 0.5373
R =
-13.0249 0.4233 -1.2647
0 -6.6258 -0.0989
0 0 -6.0738
0 0 0
0 0 0
p =
0 1 0
0 0 1
1 0 0
which I contend should be expected result. Really, I'm looking for a way to get a vector permutation matrix as well as the entire Q matrix, not the skinny factorization and this doesn't appear to be currently possible due to a bug.
For reference:
GNU Octave Version: 4.2.1
MATLAB Version: 9.3.0.713579 (R2017b)
both where run on Linux. Thanks for the hard work!
|