diff options
author | Alberto Ruiz <aruiz@um.es> | 2012-02-23 20:05:20 +0100 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2012-02-23 20:05:20 +0100 |
commit | b67148cf9e97a259c398280493829fc3cbed6582 (patch) | |
tree | a39cb543349c99d34edb2560256d5c162e6c260c | |
parent | 749c00b5afe06363e3e1ab06bc787eaa98a9e6b1 (diff) |
odeSolveV example
-rw-r--r-- | examples/ode.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/examples/ode.hs b/examples/ode.hs index 082c46c..060d4c2 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,13 @@ 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 | |||
39 | vanderpol' mu = do | ||
40 | let xdot mu t (toList->[x,v]) = fromList [v, -x + mu * v * (1-x^2)] | ||
41 | jac t (toList->[x,v]) = debug $ (2><2) [ 0 , 1 | ||
42 | , -1-2*x*v*mu, mu*(1-x**2) ] | ||
43 | ts = linspace 1000 (0,50) | ||
44 | hi = (ts@>1 - ts@>0)/100 | ||
45 | sol = toColumns $ odeSolveV BSimp hi 1E-8 1E-8 (xdot mu) (Just jac) (fromList [1,0]) ts | ||
46 | mplot sol | ||
47 | |||