I have a little haskell matrix library for fixed sized matricies on github:<br><a href="http://github.com/jvranish/VectorMatix">http://github.com/jvranish/VectorMatix</a><br>which I've just realized is horribly out of date...I'll update it tonight and probably push it to hackage too...<br>
<br>but if you're really want to stick with the [[Double]] type, <br>you can add a Foldable and Traversable instance to ZipLists and do this:<br><br>instance Foldable ZipList where<br> foldMap f (ZipList x) = foldMap f x<br>
<br>instance Traversable ZipList where<br> traverse f (ZipList x) = ZipList <$> traverse f x<br><br>toZipList a = ZipList $ fmap ZipList a<br>fromZipList a = getZipList $ fmap getZipList a<br><br>multMM :: (Num a) => [[a]] -> [[a]] -> [[a]]<br>
multMM a b = fromZipList $ multMMA (toZipList a) (toZipList b)<br><br>-- I about fell off my chair when I discovered you could do matrix multiplication like this:<br>multMMA :: (Traversable f, Num a, Applicative f, Applicative row, Applicative col, Traversable col) =><br>
row (f a) -> f (col a) -> row (col a)<br>multMMA a b = traverse (liftA2 dot a . pure) (sequenceA b)<br><br>dot :: (Foldable t, Num a, Applicative t) => t a -> t a -> a<br>dot a b = sum $ pure (*) <*> a <*> b<br>
<br><br>My matrix library uses a Gaussian elimination function (which operates on lists) as well as det and inv functions which should be easily adaptable to work on lists.<br><br>I'll make sure to push the updated code up tonight.<br>
<br>- Job<br><br><br><br><br><br><div class="gmail_quote">On Tue, Feb 2, 2010 at 7:15 AM, 조광래 <span dir="ltr"><<a href="mailto:kwangraecho@gmail.com">kwangraecho@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>define functions</div>
<div> </div>
<div>type Matrix=[[Double]]</div>
<div> </div>
<div>multMM :: Matrix -> Matrix -> Matrix --multiplies two matrices<br></div>
<div>det :: Matrix -> Double --computes the determinant of a matrix<br></div>
<div>inv :: Matrix -> Matrix --inverts a matrix</div>
<div> </div>
<div>i stuck on those problems </div>
<div> </div>
<div>can any one help me out?</div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>