When I use the QR factorization I do not get a upper triangular matrix.

8 次查看(过去 30 天)
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.

回答(1 个)

Steven Lord
Steven Lord 2015-12-11
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:"

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by