summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-05-20 16:50:32 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-05-20 16:50:32 +0100
commit5a00f4cce2894237dde647da1d067e7730d0cc29 (patch)
tree1f007575d4b7911f16c48ebc9a06d7961f3c0979 /examples
parent2df73625b693b363f7ffc399b05aaae4cbef73cd (diff)
Add the example fixing printing
Diffstat (limited to 'examples')
-rw-r--r--examples/VectorShow.hs43
-rw-r--r--examples/examples.cabal8
2 files changed, 51 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
diff --git a/examples/examples.cabal b/examples/examples.cabal
index 07ec571..286b2db 100644
--- a/examples/examples.cabal
+++ b/examples/examples.cabal
@@ -27,3 +27,11 @@ executable butcherTableau
27 hmatrix-sundials, 27 hmatrix-sundials,
28 pretty 28 pretty
29 default-language: Haskell2010 29 default-language: Haskell2010
30
31executable vectorShow
32 main-is: VectorShow.hs
33 build-depends: base >=4.10 && <4.11,
34 hmatrix,
35 hmatrix-gsl
36 default-language: Haskell2010
37