From e1b608df94dc866ede9b51bfb71ca5c89a3f09fd Mon Sep 17 00:00:00 2001 From: twells46 Date: Sun, 25 Jan 2026 11:08:43 -0600 Subject: Initial commit --- main.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 main.hs (limited to 'main.hs') diff --git a/main.hs b/main.hs new file mode 100644 index 0000000..951fedd --- /dev/null +++ b/main.hs @@ -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) -- cgit v1.2.3