diff options
author | Dominic Steinitz <dominic@steinitz.org> | 2018-05-20 16:50:32 +0100 |
---|---|---|
committer | Dominic Steinitz <dominic@steinitz.org> | 2018-05-20 16:50:32 +0100 |
commit | 5a00f4cce2894237dde647da1d067e7730d0cc29 (patch) | |
tree | 1f007575d4b7911f16c48ebc9a06d7961f3c0979 /examples | |
parent | 2df73625b693b363f7ffc399b05aaae4cbef73cd (diff) |
Add the example fixing printing
Diffstat (limited to 'examples')
-rw-r--r-- | examples/VectorShow.hs | 43 | ||||
-rw-r--r-- | examples/examples.cabal | 8 |
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 | |||
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 | ||
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 | |||
31 | executable vectorShow | ||
32 | main-is: VectorShow.hs | ||
33 | build-depends: base >=4.10 && <4.11, | ||
34 | hmatrix, | ||
35 | hmatrix-gsl | ||
36 | default-language: Haskell2010 | ||
37 | |||