Generating student-friendly random orthgonal matrices

121 Views Asked by At

I am working on randomly generated exercises for a course in linear algebra. While generating random invertible (or unimodular) matrices using repeated row and column operations is a rather easy task, generating random orthogonal or unitary matrices seems to be more involved.

The first approach that comes to mind is using products of random Householder matrices. Another approach would be starting from randomly generated unimodular matrices and applying a Gram–Schmidt orthonormalization. However, in both approaches the entries of these become very ugly algebraic expressions involving sums of roots in roots in fractions quickly.

Are there any approaches to randomly generating student friendly orthogonal or unitary matrices for exercises?

I would also be interested in just static lists of exercise-suitable orthogonal matrices up to dimension $5$ to pick from, so far I couldn't find any.

1

There are 1 best solutions below

0
On

$\def\C{{\rm Cay}}\def\S{{\rm Skew}}$Apply the Cayley transformation to a random skew-symmetric matrix $$\eqalign{ \S(X) &= \tfrac 12(X+X^T) \\ \C(X) &= (I+X)^{-1}(I-X) \quad&\implies\quad&X=\C\big(\C(X)\big) \\ Q &= \C(\S(X)) \quad&\implies\quad&I=Q^TQ \\ }$$ Julia's rational arithmetic is convenient for creating the desired student friendly matrices.

#!/usr/bin/env  julia
using LinearAlgebra

function cayley(X)
  return (I-X) / (I+X)
end

function skew(X)
  return (X-X') / 2
end

function ortho(n)
  X = convert.(Rational{Int}, rand(0:20,n,n))
  return cayley(skew(X))
end

# usage
Q2 = ortho(2)
 -21//29  -20//29
  20//29  -21//29

Q3 = ortho(3)
 -51//71  -18//71  -46//71
  26//71  -66//71   -3//71
 -42//71  -19//71   54//71