diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-02-07 09:29:50 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-02-07 09:29:50 +0000 |
commit | aef0333b5180ea79e539bd53194f1dfed20b7db5 (patch) | |
tree | 6ece2434ecacab194331120bd47d09ab04ae0f4f /examples/ode.hs | |
parent | 634683fcfab73a0bd830fef03fb9f4603ba837b6 (diff) |
added odeSolve
Diffstat (limited to 'examples/ode.hs')
-rw-r--r-- | examples/ode.hs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/ode.hs b/examples/ode.hs new file mode 100644 index 0000000..082c46c --- /dev/null +++ b/examples/ode.hs | |||
@@ -0,0 +1,34 @@ | |||
1 | import Numeric.GSL.ODE | ||
2 | import Numeric.LinearAlgebra | ||
3 | import Graphics.Plot | ||
4 | |||
5 | vanderpol mu = do | ||
6 | let xdot mu t [x,v] = [v, -x + mu * v * (1-x^2)] | ||
7 | ts = linspace 1000 (0,50) | ||
8 | sol = toColumns $ odeSolve (xdot mu) [1,0] ts | ||
9 | mplot (ts : sol) | ||
10 | mplot sol | ||
11 | |||
12 | |||
13 | harmonic w d = do | ||
14 | let xdot w d t [x,v] = [v, a*x + b*v] where a = -w^2; b = -2*d*w | ||
15 | ts = linspace 100 (0,20) | ||
16 | sol = odeSolve (xdot w d) [1,0] ts | ||
17 | mplot (ts : toColumns sol) | ||
18 | |||
19 | |||
20 | kepler v a = mplot (take 2 $ toColumns sol) where | ||
21 | xdot t [x,y,vx,vy] = [vx,vy,x*k,y*k] | ||
22 | where g=1 | ||
23 | k=(-g)*(x*x+y*y)**(-1.5) | ||
24 | ts = linspace 100 (0,30) | ||
25 | sol = odeSolve xdot [4, 0, v * cos (a*degree), v * sin (a*degree)] ts | ||
26 | degree = pi/180 | ||
27 | |||
28 | |||
29 | main = do | ||
30 | vanderpol 2 | ||
31 | harmonic 1 0 | ||
32 | harmonic 1 0.1 | ||
33 | kepler 0.3 60 | ||
34 | kepler 0.4 70 | ||