In Julia, is there any function or way to generate a random matrix with orthonormal columns of arbitrary dimensions (not necessarily square, could be rectangular/tall matrix)?
Asked
Active
Viewed 219 times
2
-
1what do you mean by a random matrix? What distribution do you want? – Oscar Smith Aug 15 '22 at 20:55
-
I guess James means this: https://stackoverflow.com/questions/38426349/how-to-create-random-orthonormal-matrix-in-python-numpy seems one way is to call SciPy via PyCall.jl – Przemyslaw Szufel Aug 15 '22 at 21:15
-
You can read https://nhigham.com/2020/04/22/what-is-a-random-orthogonal-matrix/ – Picaud Vincent Aug 16 '22 at 21:54
1 Answers
4
Since the columns of Q
in a QR decomposition are orthonormal, I think you could just perform a QR decomposition on a random matrix.
julia> using LinearAlgebra
julia> qr(rand(5)).Q
5×5 LinearAlgebra.QRCompactWYQ{Float64, Matrix{Float64}, Matrix{Float64}}:
-0.418858 -0.339672 -0.113064 -0.664132 -0.505298
-0.339672 0.918683 -0.0270673 -0.158992 -0.120967
-0.113064 -0.0270673 0.99099 -0.0529223 -0.0402654
-0.664132 -0.158992 -0.0529223 0.689136 -0.236517
-0.505298 -0.120967 -0.0402654 -0.236517 0.820048
If you don't need all 5 columns, you can just take the first k that you need.

BallpointBen
- 9,406
- 1
- 32
- 62