How do you construct random unitary matrices in Julia
An Orthogonal matrix is defined as $QQ^T=I_n=Q^TQ$ with $Q \in \mathbb{R}^{n \times n}$. This can be easily found in Julia from Manifolds.jl by the following command:
Q=rand((OrthogonalMatrices(n))).
Likewise, a unitary matrix is defined as $QQ^{} = I_n = Q^{} Q$ with * being the complex conjugate transposed. In Manifolds.jl, they have a function called UnitaryMatrices(n). However, when I write the following command: Q=rand((UnitaryMatrices(n))).
I get the following error message: "and!(::ManifoldsBase.AbstractManifold, ::Matrix{ComplexF64}) is ambiguous."
Although I didn't find how to avoid the error from the
Manifoldspackage, I did find a way to create the matrix you wished with a different package:RandomMatrices.The code looks like this:
The "magic" parameter 2 to
Haaris necessary (1 gives an orthogonal matrix). This package may have some installation issues with other packages (at least in the environment I've tested it).Hope this helps and maybe someone else will figure out how to use
Manifoldsfor this.