diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-10-15 17:17:08 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-10-15 17:17:08 +0000 |
commit | f71bcb5b4fbc68f514acc05005cc96932ced32dc (patch) | |
tree | 029b46d30d6db527048617e89a80ada59d79e0bd /examples/pinv.hs | |
parent | 9adf5ded237339dbe41db6c486993c4547396a22 (diff) |
only one pinv example
Diffstat (limited to 'examples/pinv.hs')
-rw-r--r-- | examples/pinv.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/pinv.hs b/examples/pinv.hs new file mode 100644 index 0000000..cab8fc6 --- /dev/null +++ b/examples/pinv.hs | |||
@@ -0,0 +1,20 @@ | |||
1 | import Numeric.LinearAlgebra | ||
2 | import Graphics.Plot | ||
3 | import Text.Printf(printf) | ||
4 | |||
5 | expand :: Int -> Vector Double -> Matrix Double | ||
6 | expand n x = fromColumns $ constant 1 (dim x): map (x^) [1 .. n] | ||
7 | |||
8 | polynomialModel :: Vector Double -> Vector Double -> Int | ||
9 | -> (Vector Double -> Vector Double) | ||
10 | polynomialModel x y n = f where | ||
11 | f z = expand n z <> ws | ||
12 | ws = expand n x <\> y | ||
13 | |||
14 | main = do | ||
15 | [x,y] <- (toColumns . readMatrix) `fmap` readFile "data.txt" | ||
16 | let pol = polynomialModel x y | ||
17 | let view = [x, y, pol 1 x, pol 2 x, pol 3 x] | ||
18 | putStrLn $ " x y p 1 p 2 p 3" | ||
19 | putStrLn $ format " " (printf "%.2f") $ fromColumns view | ||
20 | mplot view | ||