summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2012-02-23 20:05:20 +0100
committerAlberto Ruiz <aruiz@um.es>2012-02-23 20:05:20 +0100
commitb67148cf9e97a259c398280493829fc3cbed6582 (patch)
treea39cb543349c99d34edb2560256d5c162e6c260c
parent749c00b5afe06363e3e1ab06bc787eaa98a9e6b1 (diff)
odeSolveV example
-rw-r--r--examples/ode.hs13
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 #-}
1import Numeric.GSL.ODE 2import Numeric.GSL.ODE
2import Numeric.LinearAlgebra 3import Numeric.LinearAlgebra
3import Graphics.Plot 4import Graphics.Plot
5import Debug.Trace(trace)
6debug x = trace (show x) x
4 7
5vanderpol mu = do 8vanderpol 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
39vanderpol' 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