Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: LinearAlgebra.qr - mention that the matrix R is quadratic #33887

Open
Smeargul opened this issue Nov 18, 2019 · 3 comments
Open
Labels
domain:docs This change adds or pertains to documentation domain:linear algebra Linear algebra status:needs docs Documentation for this change is required

Comments

@Smeargul
Copy link

While the standard definition of a triangular matrix is that it is quadratic, the dimensions do not fit, and especially if you do not check the matrix, but only its rows/columns, it is easy to overlook that R is automatically truncated.

@andreasnoack
Copy link
Member

It's not always square

julia> qr(randn(2,4)).R
2×4 Array{Float64,2}:
 1.62531   1.15414    0.215677  -1.24148
 0.0      -0.115364  -0.94133    1.12214

@andreasnoack andreasnoack added the domain:linear algebra Linear algebra label Nov 19, 2019
@Smeargul
Copy link
Author

I just realized how unhelpful my comment was. I'm sorry for that.

Consider the code:

A = [ 2  -1  0; 0   1  2; 1  -1  2; 3   0  0; 0   1  2]
LinearAlgebra.qr(A)

Then this is the output:

LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}}
Q factor:
5×5 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
 -0.534522   0.311872  -0.0404557  -0.769465    0.152669
  0.0       -0.545777  -0.404557   -0.32998    -0.65542
 -0.267261   0.428825  -0.768658    0.384733   -0.0763343
 -0.801784  -0.350857   0.28319     0.384733   -0.0763343
  0.0       -0.545777  -0.404557   -0.0547528   0.731754
R factor:
3×3 Array{Float64,2}:
 -3.74166   0.801784  -0.534522
  0.0      -1.83225   -1.32546
  0.0       0.0       -3.15554

So, in this case the 5x3 matrix A is being factored into a 5x5 Q, and a 3x3 R.
(The last two (zero-)rows of R are being dropped)

This behaviour of cause makes sense, as in an m,n matrix with m>n, the last m-n rows will always be zero.
I'd only like to add this to the documentation, "That in this case, and in this case only, exactly the last m-n rows are cut from the matrix R"
(i.e. if the rank of our m,n matrix is <n, we'll still have that R is an n,n matrix, this time having zero rows)

[I'm also unsure why the matrix multiplication of an 5x5 and an 3x3 matrix works when using LinearAlgebra.qr(A).Q*LinearAlgebra.qr(A).R, while in general this would throw an error]

@andreasnoack
Copy link
Member

It would be great if you could prepare a PR with the changes you think would be helpful.

@ViralBShah ViralBShah added domain:docs This change adds or pertains to documentation status:needs docs Documentation for this change is required labels Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation domain:linear algebra Linear algebra status:needs docs Documentation for this change is required
Projects
None yet
Development

No branches or pull requests

3 participants