When I use the QR factorization I do not get a upper triangular matrix.
9 views (last 30 days)
Show older comments
According to the documentation if A is an mxn matrix the function R=qr(A) should return a mxn upper triangular matrix. If I use the following example:
A=[1 0 0 0 ; 0 1 0 1; 0 1 1 0];
R=qr(A)
I get the following output, which is not an upper triangular matrix
R=
1.0000 0 0 0
0 -1.4142 -0.7071 -0.7071
0 0.4142 0.7071 -0.7071
Likewise if I try to compute the "economy size" QR-decomposition via R=qr(A, 0) I also get a matrix that is not upper triangular:
ans =
1.0000 0 0 0
0 -1.4142 -0.7071 -0.7071
0 0.4142 0.7071 -0.7071
If on the other hand I use the code:
A=[1 0 0 0 ; 0 1 0 1; 0 1 1 0];
[Q,R,P]=qr(A);
R = 1.0000 0 0 0
0 -1.4142 -0.7071 -0.7071
0 0 0.7071 -0.7071
I get that R is an upper triangular matrix. Am I misunderstanding the documentation for qr? Ideally I would like to use qr(A,0) to compute the economy QR decomposition of a matrix, but have the output be upper triangular.
0 Comments
Answers (1)
Steven Lord
on 11 Dec 2015
Yes, you are misunderstanding the documentation. On the documentation page, the section of the description that describes the syntax "R = qr(A)" appears right after the statement "If A is sparse:"
Your matrix A is full not sparse, and so what you're actually computing is "X = qr(A) and X = qr(A,0) return a matrix X such that triu(X) is the upper triangular factor R." from the section "If A is full:"
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!