Gaussian elimination: Difference between revisions
Content added Content deleted
(From scratch) |
m (→From scratch) |
||
Line 1,416: | Line 1,416: | ||
===From scratch=== |
===From scratch=== |
||
<lang Haskell> |
<lang Haskell> |
||
isMatrix xs = null xs || all ((== (length.head $ xs)).length) xs |
isMatrix xs = null xs || all ((== (length.head $ xs)).length) xs |
||
Line 1,446: | Line 1,445: | ||
go (x:xs) (y:ys) zs = go xs ys $ (val x y zs):zs |
go (x:xs) (y:ys) zs = go xs ys $ (val x y zs):zs |
||
triangle::Num a => [[a]] -> [[a]] -> ([[a]],[[a]]) |
triangle::(Num a, Ord a) => [[a]] -> [[a]] -> ([[a]],[[a]]) |
||
triangle xs bs = triang ([],[]) (xs,bs) |
triangle xs bs = triang ([],[]) (xs,bs) |
||
where |
where |
||
Line 1,454: | Line 1,453: | ||
where ((us@(u:tus)):uss,cs:css) = bubble zs |
where ((us@(u:tus)):uss,cs:css) = bubble zs |
||
bubble:: |
bubble::(Num a, Ord a) => ([[a]],[[a]]) -> ([[a]],[[a]]) |
||
bubble (xs,bs) = (go xs, go bs) |
bubble (xs,bs) = (go xs, go bs) |
||
where |
where |
||
idmax = snd. |
idmax = snd.minimum.flip zip [0..].map (negate.abs.head) $ xs |
||
go ys = let (us,vs) = splitAt idmax ys in vs ++ us |
go ys = let (us,vs) = splitAt idmax ys in vs ++ us |
||