Gaussian elimination: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, aligned statements better.) |
|||
Line 1,529: | Line 1,529: | ||
===Another example=== |
===Another example=== |
||
We use Rational numbers for having more precision. a % b is the rational a / b. |
We use Rational numbers for having more precision. a % b is the rational a / b. |
||
<lang Haskell> |
<lang Haskell>mult:: Num a => [[a]] -> [[a]] -> [[a]] |
||
mult uss vss = map (foldl (zipWith (+)) ts . zipWith (\vs u -> map (u*) vs) vss) uss |
|||
where ts = map (const 0).concat $ take 1 vss |
|||
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 |
|||
bubble::([a] -> c) -> (c -> c -> Bool) -> [[a]] -> [[b]] -> ([[a]],[[b]]) |
bubble::([a] -> c) -> (c -> c -> Bool) -> [[a]] -> [[b]] -> ([[a]],[[b]]) |
||
Line 1,713: | Line 1,700: | ||
True |
True |
||
</pre> |
</pre> |
||
===Determinant and permutation matrix are given=== |
===Determinant and permutation matrix are given=== |
||
<lang Haskell> |
<lang Haskell> |