Gaussian elimination: Difference between revisions
Content added Content deleted
Line 1,696: | Line 1,696: | ||
===Determinant and permutation matrix are given=== |
===Determinant and permutation matrix are given=== |
||
<lang Haskell> |
<lang Haskell>mult:: Num a => [[a]] -> [[a]] -> [[a]] |
||
mult uss vss = map ((\xs -> if null xs then [] else foldl1 (zipWith (+)) xs). zipWith (\vs u -> map (u*) vs) vss) uss |
|||
foldlZipWith _ _ u [] _ = u |
|||
foldlZipWith _ _ u _ [] = u |
|||
foldlZipWith f g u (x:xs) (y:ys) = foldlZipWith f g (g u (f x y)) xs ys |
|||
foldl1ZipWith::(a -> b -> c) -> (c -> c -> c) -> [a] -> [b] -> c |
|||
foldl1ZipWith _ _ [] _ = error "First list is empty" |
|||
foldl1ZipWith _ _ _ [] = error "Second list is empty" |
|||
foldl1ZipWith f g (x:xs) (y:ys) = foldlZipWith f g (f x y) xs ys |
|||
multAdd::(a -> b -> c) -> (c -> c -> c) -> [[a]] -> [[b]] -> [[c]] |
|||
multAdd f g xs ys = map (\us -> foldl1ZipWith (\u vs -> map (f u) vs) (zipWith g) us ys) xs |
|||
mult:: Num a => [[a]] -> [[a]] -> [[a]] |
|||
mult xs ys = multAdd (*) (+) xs ys |
|||
triangle::(Fractional a, Ord a) => [[a]] -> [[a]] -> (a,[(([a],[a]),Int)]) |
triangle::(Fractional a, Ord a) => [[a]] -> [[a]] -> (a,[(([a],[a]),Int)]) |