Search code examples
haskellmatrixorthogonal

How do you compute an orthogonal basis of a matrix using hmatrix?


orth(somematrix) is built into MATLAB but doesn't seem to be available in the Haskell hmatrix library.


Solution

  • import Numeric.LinearAlgebra    
    
    orth :: Field a => Matrix a -> [Vector a]
    orth m = toColumns $ fst $ qr m
    

    or point-free

    orth = toColumns . fst . qr
    

    Wikipedia has an explanation.