using LinearAlgebra
A = rand(4,4)
4×4 Array{Float64,2}: 0.330869 0.843845 0.0623888 0.398208 0.8661 0.204488 0.138221 0.218923 0.741009 0.775278 0.576722 0.9775 0.87276 0.139498 0.072938 0.983904
Q,R = qr(A)
LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} Q factor: 4×4 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}: -0.224588 0.76522 0.603058 -0.017861 -0.587892 -0.292547 0.130273 -0.742852 -0.502982 0.437253 -0.739298 0.0962124 -0.592413 -0.371031 0.269792 0.662266 R factor: 4×4 Array{Float64,2}: -1.47323 -0.782326 -0.428561 -1.29268 0.0 0.873139 0.232416 0.303028 0.0 0.0 -0.351061 -0.188552 0.0 0.0 0.0 0.575913
round.(Q'Q, digits=0)
4×4 Array{Float64,2}: 1.0 0.0 0.0 -0.0 0.0 1.0 -0.0 -0.0 0.0 -0.0 1.0 0.0 -0.0 -0.0 0.0 1.0
round.(Q*Q', digits=0)
4×4 Array{Float64,2}: 1.0 0.0 -0.0 -0.0 0.0 1.0 0.0 -0.0 -0.0 0.0 1.0 0.0 -0.0 -0.0 0.0 1.0
A ≈ Q * R
true
Q * R
4×4 Array{Float64,2}: 0.330869 0.843845 0.0623888 0.398208 0.8661 0.204488 0.138221 0.218923 0.741009 0.775278 0.576722 0.9775 0.87276 0.139498 0.072938 0.983904
A
4×4 Array{Float64,2}: 0.330869 0.843845 0.0623888 0.398208 0.8661 0.204488 0.138221 0.218923 0.741009 0.775278 0.576722 0.9775 0.87276 0.139498 0.072938 0.983904
A = rand(5,3)
5×3 Array{Float64,2}: 0.657045 0.214426 0.0462177 0.268263 0.208357 0.269215 0.410459 0.948475 0.756601 0.391947 0.683485 0.28925 0.949405 0.999374 0.570501
Q,R = qr(A)
Q = Q[:,1:3] # make sure we have the first three columns
5×3 Array{Float64,2}: -0.499955 -0.62267 0.00434913 -0.204125 -0.0946497 -0.628421 -0.312324 0.686918 -0.424575 -0.298239 0.362414 0.645285 -0.722416 0.0110753 0.0917176
Q
5×3 Array{Float64,2}: -0.499955 -0.62267 0.00434913 -0.204125 -0.0946497 -0.628421 -0.312324 0.686918 -0.424575 -0.298239 0.362414 0.645285 -0.722416 0.0110753 0.0917176
R
3×3 Array{Float64,2}: -1.31421 -1.37177 -0.81277 0.0 0.75706 0.57661 0.0 0.0 -0.251239
Q * R
5×3 Array{Float64,2}: 0.657045 0.214426 0.0462177 0.268263 0.208357 0.269215 0.410459 0.948475 0.756601 0.391947 0.683485 0.28925 0.949405 0.999374 0.570501
A
5×3 Array{Float64,2}: 0.657045 0.214426 0.0462177 0.268263 0.208357 0.269215 0.410459 0.948475 0.756601 0.391947 0.683485 0.28925 0.949405 0.999374 0.570501
A ≈ Q * R
true
round.(Q'Q, digits=0)
3×3 Array{Float64,2}: 1.0 -0.0 -0.0 -0.0 1.0 -0.0 -0.0 -0.0 1.0
Q * Q'
5×5 Array{Float64,2}: 0.637693 0.158256 -0.273422 -0.0737523 0.354678 0.158256 0.445538 0.265548 -0.378935 0.0887777 -0.273422 0.265548 0.749666 0.0681243 0.194295 -0.0737523 -0.378935 0.0681243 0.636683 0.27865 0.354678 0.0887777 0.194295 0.27865 0.53042