summaryrefslogtreecommitdiff
path: root/examples/pinv1.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-21 18:28:08 +0000
commit0198366bba7a5f2d67338633f9eb90889ffc31b2 (patch)
tree4897d90233b333ee2092e63a4b74c7bcb2d22577 /examples/pinv1.hs
parentd4cb2692f9dae748da23371057a983deca4b2f80 (diff)
add examples
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])