summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-02-07 09:29:50 +0000
committerAlberto Ruiz <aruiz@um.es>2010-02-07 09:29:50 +0000
commitaef0333b5180ea79e539bd53194f1dfed20b7db5 (patch)
tree6ece2434ecacab194331120bd47d09ab04ae0f4f /examples
parent634683fcfab73a0bd830fef03fb9f4603ba837b6 (diff)
added odeSolve
Diffstat (limited to 'examples')
-rw-r--r--examples/Real.hs (renamed from examples/HMatrixReal.hs)2
-rw-r--r--examples/ode.hs34
2 files changed, 35 insertions, 1 deletions
diff --git a/examples/HMatrixReal.hs b/examples/Real.hs
index 0edff10..b32a961 100644
--- a/examples/HMatrixReal.hs
+++ b/examples/Real.hs
@@ -1,7 +1,7 @@
1 1
2-- Alternative interface and utilities for creation of real arrays, useful to work in interactive mode. 2-- Alternative interface and utilities for creation of real arrays, useful to work in interactive mode.
3 3
4module HMatrixReal( 4module Real(
5 module Numeric.LinearAlgebra, 5 module Numeric.LinearAlgebra,
6 (<>), (*>), (<*), (<\>), (\>), 6 (<>), (*>), (<*), (<\>), (\>),
7 vector, 7 vector,
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 @@
1import Numeric.GSL.ODE
2import Numeric.LinearAlgebra
3import Graphics.Plot
4
5vanderpol 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
13harmonic 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
20kepler 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
29main = do
30 vanderpol 2
31 harmonic 1 0
32 harmonic 1 0.1
33 kepler 0.3 60
34 kepler 0.4 70