diff options
Diffstat (limited to 'examples/VectorShow.hs')
-rw-r--r-- | examples/VectorShow.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/VectorShow.hs b/examples/VectorShow.hs new file mode 100644 index 0000000..c56d772 --- /dev/null +++ b/examples/VectorShow.hs | |||
@@ -0,0 +1,43 @@ | |||
1 | {-# LANGUAGE DataKinds #-} | ||
2 | |||
3 | module Main | ||
4 | ( main | ||
5 | ) where | ||
6 | |||
7 | import Numeric.LinearAlgebra.Static | ||
8 | import qualified Numeric.LinearAlgebra as LA | ||
9 | import qualified Numeric.GSL.Minimization as Min | ||
10 | |||
11 | u :: R 4 | ||
12 | u = vec4 10 20 30 40 | ||
13 | |||
14 | v :: R 5 | ||
15 | v = vec2 5 0 & 0 & 3 & 7 | ||
16 | |||
17 | b :: L 4 3 | ||
18 | b = matrix | ||
19 | [ 2, 0,-1 | ||
20 | , 1, 1, 7 | ||
21 | , 5, 3, 1 | ||
22 | , 2, 8, 0 ] :: L 4 3 | ||
23 | |||
24 | w :: R 10 | ||
25 | w = vector [1..10] :: R 10 | ||
26 | |||
27 | f :: [Double] -> Double | ||
28 | f [x,y] = 10*(x-1)^(2::Int) + 20*(y-2)^(2::Int) + 30 | ||
29 | f _ = error "f only defined for exactly 2 elements" | ||
30 | |||
31 | main :: IO () | ||
32 | main = do | ||
33 | print u | ||
34 | print v | ||
35 | print b | ||
36 | print w | ||
37 | print $ diag u | ||
38 | print (eye + 2 :: Sq 4) | ||
39 | print $ LA.diag (LA.fromList [1,2,3 :: Double]) | ||
40 | -- | ||
41 | let (s,p) = Min.minimize Min.NMSimplex2 1E-2 30 [1,1] f [5,7] | ||
42 | print s | ||
43 | print p | ||