summaryrefslogtreecommitdiff
path: root/examples/VectorShow.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/VectorShow.hs')
-rw-r--r--examples/VectorShow.hs43
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
3module Main
4 ( main
5 ) where
6
7import Numeric.LinearAlgebra.Static
8import qualified Numeric.LinearAlgebra as LA
9import qualified Numeric.GSL.Minimization as Min
10
11u :: R 4
12u = vec4 10 20 30 40
13
14v :: R 5
15v = vec2 5 0 & 0 & 3 & 7
16
17b :: L 4 3
18b = matrix
19 [ 2, 0,-1
20 , 1, 1, 7
21 , 5, 3, 1
22 , 2, 8, 0 ] :: L 4 3
23
24w :: R 10
25w = vector [1..10] :: R 10
26
27f :: [Double] -> Double
28f [x,y] = 10*(x-1)^(2::Int) + 20*(y-2)^(2::Int) + 30
29f _ = error "f only defined for exactly 2 elements"
30
31main :: IO ()
32main = 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