diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-09-21 18:28:08 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-09-21 18:28:08 +0000 |
commit | 0198366bba7a5f2d67338633f9eb90889ffc31b2 (patch) | |
tree | 4897d90233b333ee2092e63a4b74c7bcb2d22577 /examples/pinv1.hs | |
parent | d4cb2692f9dae748da23371057a983deca4b2f80 (diff) |
add examples
Diffstat (limited to 'examples/pinv1.hs')
-rw-r--r-- | examples/pinv1.hs | 18 |
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 | ||
2 | import LinearAlgebra | ||
3 | |||
4 | |||
5 | prepSyst :: Int -> Matrix Double -> (Matrix Double, Vector Double) | ||
6 | prepSyst n d = (a,b) where | ||
7 | [x,b] = toColumns d | ||
8 | a = fromColumns $ 1+0*x : map (x^) [1 .. n] | ||
9 | |||
10 | main = 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]) | ||