[Haskell-cafe] matrix question

Richard O'Keefe ok at cs.otago.ac.nz
Tue Feb 2 18:34:53 EST 2010

On Feb 3, 2010, at 1:15 AM, 조광래 wrote:

> define functions
> type Matrix=[[Double]]
> multMM :: Matrix -> Matrix -> Matrix --multiplies two matrices
> det :: Matrix -> Double --computes the determinant of a matrix
> inv :: Matrix -> Matrix --inverts a matrix
> i stuck on those problems

Stuck how, exactly?  Writing a good matrix inversion procedure
is seriously tricky in any programming language (unless you
are using rational arithmetic, in which case it's tricky in a
different way).  Indeed, I think every book I've come across
says "DON'T compute multMM x (inv y)" but instead use a "solve"

You'll find matrix multiplication easy enough if you draw a
few diagrams and think in terms of operations on rows and
columns rather than in terms of array elements.

For matrix inversion, Gaussian elimination with partial pivoting
is tedious rather than difficult.  The same conversion-to-triangular
process will give you determinant.

More information about the Haskell-Cafe mailing list