summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Steinitz <dominic@steinitz.org>2018-04-22 08:25:50 +0100
committerDominic Steinitz <dominic@steinitz.org>2018-04-22 08:25:50 +0100
commit93c28276e163c8c620a3d1461f4270c7a86763cf (patch)
tree6313b2de755d155a2baa31f02c59d79967eb2e23
parentf2b5659c792b75606256f3be6200650e60695777 (diff)
Fix warnings
-rw-r--r--examples/sundials.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/examples/sundials.hs b/examples/sundials.hs
index 1643540..99f662d 100644
--- a/examples/sundials.hs
+++ b/examples/sundials.hs
@@ -1,10 +1,14 @@
1{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
2
1{-# LANGUAGE ViewPatterns #-} 3{-# LANGUAGE ViewPatterns #-}
4
2import Numeric.Sundials.ARKode.ODE 5import Numeric.Sundials.ARKode.ODE
3import Numeric.LinearAlgebra 6import Numeric.LinearAlgebra
4import Graphics.Plot 7import Graphics.Plot
5 8
6vanderpol mu = do 9vanderpol mu = do
7 let xdot mu t [x,v] = [v, -x + mu * v * (1-x^2)] 10 let xdot nu _t [x,v] = [v, -x + nu * v * (1-x*x)]
11 xdot _ _ _ = error "vanderpol RHS not defined"
8 ts = linspace 1000 (0,50) 12 ts = linspace 1000 (0,50)
9 sol = toColumns $ odeSolve (xdot mu) [1,0] ts 13 sol = toColumns $ odeSolve (xdot mu) [1,0] ts
10 mplot (ts : sol) 14 mplot (ts : sol)
@@ -12,16 +16,18 @@ vanderpol mu = do
12 16
13 17
14harmonic w d = do 18harmonic w d = do
15 let xdot w d t [x,v] = [v, a*x + b*v] where a = -w^2; b = -2*d*w 19 let xdot u dd _t [x,v] = [v, a*x + b*v] where a = -u*u; b = -2*dd*u
20 xdot _ _ _ _ = error "harmonic RHS not defined"
16 ts = linspace 100 (0,20) 21 ts = linspace 100 (0,20)
17 sol = odeSolve (xdot w d) [1,0] ts 22 sol = odeSolve (xdot w d) [1,0] ts
18 mplot (ts : toColumns sol) 23 mplot (ts : toColumns sol)
19 24
20 25
21kepler v a = mplot (take 2 $ toColumns sol) where 26kepler v a = mplot (take 2 $ toColumns sol) where
22 xdot t [x,y,vx,vy] = [vx,vy,x*k,y*k] 27 xdot _t [x,y,vx,vy] = [vx,vy,x*k,y*k]
23 where g=1 28 where g=1
24 k=(-g)*(x*x+y*y)**(-1.5) 29 k=(-g)*(x*x+y*y)**(-1.5)
30 xdot _ _ = error "kepler RHS not defined"
25 ts = linspace 100 (0,30) 31 ts = linspace 100 (0,30)
26 sol = odeSolve xdot [4, 0, v * cos (a*degree), v * sin (a*degree)] ts 32 sol = odeSolve xdot [4, 0, v * cos (a*degree), v * sin (a*degree)] ts
27 degree = pi/180 33 degree = pi/180
@@ -37,9 +43,11 @@ main = do
37 43
38-- example of odeSolveV with jacobian 44-- example of odeSolveV with jacobian
39vanderpol' mu = do 45vanderpol' mu = do
40 let xdot mu t (toList->[x,v]) = fromList [v, -x + mu * v * (1-x^2)] 46 let xdot nu _t (toList->[x,v]) = fromList [v, -x + nu * v * (1-x*x)]
41 jac t (toList->[x,v]) = (2><2) [ 0 , 1 47 xdot _ _ _ = error "vanderpol' RHS not defined"
48 jac _ (toList->[x,v]) = (2><2) [ 0 , 1
42 , -1-2*x*v*mu, mu*(1-x**2) ] 49 , -1-2*x*v*mu, mu*(1-x**2) ]
50 jac _ _ = error "vanderpol' Jacobian not defined"
43 ts = linspace 1000 (0,50) 51 ts = linspace 1000 (0,50)
44 hi = pure $ (ts!1 - ts!0) / 100.0 52 hi = pure $ (ts!1 - ts!0) / 100.0
45 sol = toColumns $ odeSolveV (SDIRK_5_3_4 jac) hi 1E-8 1E-8 (xdot mu) (fromList [1,0]) ts 53 sol = toColumns $ odeSolveV (SDIRK_5_3_4 jac) hi 1E-8 1E-8 (xdot mu) (fromList [1,0]) ts