summaryrefslogtreecommitdiff
path: root/examples/pinv1.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pinv1.hs')
-rw-r--r--examples/pinv1.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/pinv1.hs b/examples/pinv1.hs
new file mode 100644
index 0000000..76fa0a9
--- /dev/null
+++ b/examples/pinv1.hs
@@ -0,0 +1,18 @@
1-- initial check for the polynomial model example
2import LinearAlgebra
3
4
5prepSyst :: Int -> Matrix Double -> (Matrix Double, Vector Double)
6prepSyst n d = (a,b) where
7 [x,b] = toColumns d
8 a = fromColumns $ 1+0*x : map (x^) [1 .. n]
9
10main = do
11 dat <- readMatrix `fmap` readFile "data.txt"
12 let (a,b) = prepSyst 3 dat
13 putStr "Coefficient matrix:\n"
14 dispR 3 a
15 putStr "Desired values:\n"
16 print b
17 putStr "\nLeast Squares Solution:\n"
18 print $ pinv a <> b -- equivalent to: linearSolveLSR a (fromColumns [b])