StaticArrays.jl icon indicating copy to clipboard operation
StaticArrays.jl copied to clipboard

orthonormalization has different result from Array

Open kanubacode opened this issue 3 years ago • 1 comments

(Practice) julia> m4a = [1.01 0 0 0; 0 1.0001 0 0; 0 0 1.003 0; 0 0 0 1]
4×4 Matrix{Float64}:
 1.01  0.0     0.0    0.0
 0.0   1.0001  0.0    0.0
 0.0   0.0     1.003  0.0
 0.0   0.0     0.0    1.0

(Practice) julia> m4b = @SMatrix [1.01 0 0 0; 0 1.0001 0 0; 0 0 1.003 0; 0 0 0 1]
4×4 SMatrix{4, 4, Float64, 16} with indices SOneTo(4)×SOneTo(4):
 1.01  0.0     0.0    0.0
 0.0   1.0001  0.0    0.0
 0.0   0.0     1.003  0.0
 0.0   0.0     0.0    1.0

(Practice) julia> qr(m4a).Q
4×4 QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}}:
 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

(Practice) julia> qr(m4b).Q
4×4 SMatrix{4, 4, Float64, 16} with indices SOneTo(4)×SOneTo(4):
 -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

kanubacode avatar Jul 13 '22 02:07 kanubacode

I don't know if it makes any guarantees about sign, but it is correct with respect to Q being orthogonal, and Q*R approximately equaling the original matrix.

julia> m4b = @SMatrix [1.01 0 0 0; 0 1.0001 0 0; 0 0 1.003 0; 0 0 0 1];

julia> f = qr(m4b);

julia> f.Q
4×4 SMatrix{4, 4, Float64, 16} with indices SOneTo(4)×SOneTo(4):
 -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

julia> f.Q * f.Q' ≈ I
true

julia> f.Q * f.R ≈ m4b
true

chriselrod avatar Jul 13 '22 04:07 chriselrod