diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | main.hs | 29 |
2 files changed, 32 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc2e12b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Matrix + +An unfinished matrix calculator written in Haskell. @@ -0,0 +1,29 @@ +--innerProduct :: [Int] -> [Int] -> Int +dotProduct [] [] = 0 +dotProduct (x:xs) (y:ys) = x * y + dotProduct xs ys + +--oneRow row [[], []] = [] +oneRow row mat@(x:xs) = if null x + then [] + else dotProduct row (map head mat) : oneRow row (map tail mat) + +almostMatrixMult mat1 mat2 = if null mat1 + then [[]] + else oneRow (head mat1) mat2 : almostMatrixMult (tail mat1) mat2 + +matrixMult mat1 mat2 = [a | a <- almostMatrixMult mat1 mat2, not $ null a] + + +dropNth xs n = map fst $ filter ((n/=) . snd) $ zip xs [1..] + +minor mat i = dropNth (map tail mat) i + +cofac mat i = ((-1) ^ (i+1)) * det (minor mat i) + +expFac mat i = head (mat!!(i-1)) * cofac mat i + +det [[a, b], [c, d]] = a * d - b * c +det mat = helper mat 1 where + helper mat i = if i >= length mat + then expFac mat i + else expFac mat i + helper mat (i+1) |