aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortwells46 <tom@wellsth.com>2026-01-25 11:08:43 -0600
committertwells46 <tom@wellsth.com>2026-01-25 11:08:43 -0600
commite1b608df94dc866ede9b51bfb71ca5c89a3f09fd (patch)
tree9cf7cbf46550a979230a960d900f1d3c4c1bd5be
Initial commitHEADmain
-rw-r--r--README.md3
-rw-r--r--main.hs29
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.
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)