diff options
Diffstat (limited to 'examples/ode.hs')
-rw-r--r-- | examples/ode.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/ode.hs b/examples/ode.hs index 082c46c..dc6e0ec 100644 --- a/examples/ode.hs +++ b/examples/ode.hs | |||
@@ -1,6 +1,9 @@ | |||
1 | {-# LANGUAGE ViewPatterns #-} | ||
1 | import Numeric.GSL.ODE | 2 | import Numeric.GSL.ODE |
2 | import Numeric.LinearAlgebra | 3 | import Numeric.LinearAlgebra |
3 | import Graphics.Plot | 4 | import Graphics.Plot |
5 | import Debug.Trace(trace) | ||
6 | debug x = trace (show x) x | ||
4 | 7 | ||
5 | vanderpol mu = do | 8 | vanderpol mu = do |
6 | let xdot mu t [x,v] = [v, -x + mu * v * (1-x^2)] | 9 | let xdot mu t [x,v] = [v, -x + mu * v * (1-x^2)] |
@@ -32,3 +35,16 @@ main = do | |||
32 | harmonic 1 0.1 | 35 | harmonic 1 0.1 |
33 | kepler 0.3 60 | 36 | kepler 0.3 60 |
34 | kepler 0.4 70 | 37 | kepler 0.4 70 |
38 | vanderpol' 2 | ||
39 | |||
40 | -- example of odeSolveV with jacobian | ||
41 | vanderpol' mu = do | ||
42 | let xdot mu t (toList->[x,v]) = fromList [v, -x + mu * v * (1-x^2)] | ||
43 | jac t (toList->[x,v]) = (2><2) [ 0 , 1 | ||
44 | , -1-2*x*v*mu, mu*(1-x**2) ] | ||
45 | ts = linspace 1000 (0,50) | ||
46 | hi = (ts@>1 - ts@>0)/100 | ||
47 | sol = toColumns $ odeSolveV (MSBDF jac) hi 1E-8 1E-8 (xdot mu) (fromList [1,0]) ts | ||
48 | mplot sol | ||
49 | |||
50 | |||