Dynamical Systems and Numerical Integration
Dynamical Systems and Numerical Integration
Orestis Malaspinas
1/78
General introduction to dynamical
systems
2/78
What is a dynamical system?
3/78
Different classes of descriptions
4/78
Generality of the description: continuous case
What happens if we have second derivatives?
ṡ + s̈ = f (s)
Let us then define
ṡ = y,
ẏ = f (s) − y.
By defining u(t) ≡ (s(t), y(t)) we have a system of the form
u̇ = g(u).
5/78
Generality of the description: discrete case
“Second derivatives” equivalent to presence of a t − ∆t term
s(t + ∆t) = f (s(t)) + s(t − ∆t).
Similarly to continuous case
y(t + ∆t) = s(t),
s(t + ∆t) = f (s(t)) + y(t),
and by defining u(t) ≡ (s(t), y(t)) we have a system of the form
u(t + ∆t) = g(u(t)).
6/78
Generality of the description: continuous case
What happens if f explicitly depends on t?
ṡ = f (s, t)
Let us then define
ṡ = f (s, y)
ẏ = 1,
with y(0) = 0. By defining u(t) ≡ (s(t), y(t)) we have a system of
the form
u̇ = g(u).
7/78
End of module
General introduction to dynamical
systems
Coming next
The random walk
8/78
The random walk
9/78
The random walk
Time evolution of particles, drunk people, ...
x(t + ∆t) = x(t) + ∆t · vx (t),
y(t + ∆t) = y(t) + ∆t · vy (t),
where (vx , vy ) is chosen randomly in the ensemble
{(∆x/∆t, 0), (−∆x/∆t, 0), (0, 0), (0, ∆y/∆t), (0, −∆y/∆t)},
where ∆x and ∆y are the length of the displacements in direction x
and y.
10/78
The random walk: illustration
11/78
The random walk: illustration
12/78
The random walk: illustration
13/78
The random walk: mathematical analysis
What is the “average” behavior of many random walkers?
• Initial position of the walker is (x(0), y(0)) = (x0 , y0 ).
• After a time t = N · ∆t the position of a random walker is
x(t) = x(t − ∆t) + ∆t · vx (t − ∆t)
= x(t − 2∆t) + ∆t · (vx (t − 2∆t) + vx (t − ∆t)) ,
XN
= x(0) + ∆t vx (t − n · ∆t).
n=1
14/78
The random walk: mathematical analysis
What is the average position?
N
X
hx(t)i = x0 + ∆t hvx (t − n · ∆t)i,
n=1
16/78
The random walk: mathematical analysis
Statistical independence
⇒ hvx (t − m∆t)vx (t − n∆t)i = 0, m 6= n.
And for m = n
∆x2 ∆x2 2∆x2
1 3 1
hv2x i = + ×0+ = .
5 ∆t2 5 5 ∆t2 5∆t2
17/78
The random walk: mathematical analysis
18/78
The random walk: mathematical analysis
Doing similarly for dy2 on gets
r
q
2 2
4∆x2
d = dx + dy = t .
5∆t
∆x2
Finally by defining the diffusion coefficient D ≡ 5∆t
√
d = 4Dt.
Equivalent to
∂t ρ(x, y, t) = D(∂x2 + ∂y2 )ρ(x, y, t).
19/78
The random walk: 2D diffusion
20/78
The random walk: N = 100
21/78
The random walk: N = 1000
22/78
The random walk: N = 10000
23/78
The random walk: N = 100000
24/78
End of module
The random walk
Coming next
Growth of a population
25/78
Growth of a population
26/78
Growth of a population
• Let us note the number of individuals of a population P(t), and
P(0) = P0 .
• Only two processes are affecting the number of individuals: the
number of births B(t) and the number of deaths D(t).
• The variation of P(t) can be expressed as
Ṗ(t) = B(t) − D(t).
• A possible model for births and deaths is given by
B(t) = rb P(t), D(t) = rd P(t).
27/78
Growth of a population
28/78
Growth of a population
140
120
• r > 0 exponential growth. 100
80
P (t)
• r < 0 exponential decay. 60
• r = 0 constant. 40
20
0
0 1 2 3 4 5 6 7 8 9
t
29/78
Growth of a population
30/78
Growth of a population
90
80
The solution is a logistic function 70
60
P (t)
C 50
P(t) = C−P0 −vt 40
1+ P0 e 30
20
10
0 1 2 3 4 5 6 7 8 9
t
31/78
Growth of a population
32/78
End of module
Growth of a population
Coming next
Balance equations
33/78
Balance equations I
34/78
Balance equations
| {z } | {z rate} − destruction
variation of a quantity = creation | {z rate} .
ex: Ṗ ex: B(t) ex: D(t)
35/78
Balance equations
36/78
Lotka–Volterra model (“Prey-Predator”)
37/78
Lotka–Volterra model (“Prey-Predator”)
Time evolution 6
5
Periodicity 4
a(t), c(t)
3
2
1
0
0 5 10 15 20 25 30
t
38/78
Lotka–Volterra model (“Prey-Predator”)
Parametric plot 10
8
Initial condition 6
sensitivity
c
4
0
0 2 4 6 8 10
a
39/78
End of module
Balance equations I
Coming next
Balance equations II
40/78
Balance equations II
41/78
Space–time dependent equations
43/78
The continuity equation
• Let us define ρ(t, x) the volume density of the property one wants
to study (mass, electric charge, ...)
Z
s(t) = ρ(t, x)dV.
V
44/78
The continuity equation
R
By defining Σ = V σdV
I
ṡ + j · ndS = Σ
∂V
46/78
Example: The Navier–Stokes equations, ρ → ρu
47/78
End of module
Balance equations II
Coming next
Integration of ordinary differential
equations
48/78
Integration of ordinary differential
equations
49/78
Integration of ordinary differential equations
50/78
Example: Growth of a population
s
ṡ = f (s, t), f (s, t) = v 1 − s.
C
90
80
C 70
s(t) = 60
C−s0
P (t)
1+ s0 e−vt 50
40
30
20
10
0 1 2 3 4 5 6 7 8 9
t
51/78
Explicit Euler scheme, ṡ = f (s, t)
52/78
Explicit Euler scheme (continued)
Iteratively one finds the explicit or forward Euler scheme
s(tn+1 ) = s(tn ) + ∆t · f (s, tn ), tn+1 = tn + ∆t.
Remarks
• It looks a lot like a discrete dynamical system!
• s(tn+1 ) depends explicitly on s(tn ).
• Straightforward to implement on a computer.
53/78
Example: growth of a population
54/78
End of module
Integration of ordinary differential
equations
Coming next
Error of the approximation
55/78
Error of the approximation
56/78
Error of the approximation
Evaluation of the error
v
u N
u 1 X
E(∆t) = t (s(ti ) − s∆t (ti ))2 ,
N+1
i=0
Remark
• If no analytical solution exists one can replace s(ti ) → smin(∆t) (ti ).
57/78
Evaluation of the error
58/78
Evaluation of the error
Defining Ei = s(ti ) − s∆t (ti ), we have
E0 = s(t0 ) − s∆t (t0 ) = 0, · · · ,
EN = s(tN ) − s∆t (tN ) = NO(∆t2 ).
Therefore
v v
u N u N
u O(∆t4 ) X √
u 1 X
2
E=t Ei ∼ t i ∼ ∆t4 N 2 ∼ O(∆t),
2
N+1 N+1
i=0 i=0
60/78
End of module
Error of the approximation
Coming next
Implicit Euler scheme
61/78
Implicit Euler scheme
62/78
Stability of explicit schemes
63/78
The implicit Euler scheme
64/78
Implicit Euler scheme (continued)
0
sj+1 = sj − 10∆tsj+1 , sj+1 = sj (1−10∆t).
−1
−2 sj+1 = sj /(1 + 10∆t).
−3
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6
t • Instability solved.
65/78
Explicit vs Implicit (continued)
Graphical interpetation
Explicit Implicit
2.6 2.6
2.4 2.4
2.2 2.2
2.0 2.0
1.8 1.8
s(t)
s(t)
1.6 1.6
1.4 1.4
1.2 1.2
1.0 1.0
0.8 0.8
−0.5 0.0 0.5 1.0 1.5 2.0 −0.5 0.0 0.5 1.0 1.5 2.0
t t
66/78
Explicit vs Implicit
Explicit Implicit
• Explicit equation to solve • Implicit equation to solve
• Conditionally stable (on stiff problems) • Unconditionnaly stable
• Simple implementation • Difficult implementation
Explicit/Implicit solution (left) and error (right) on the population growth problem.
67/78
End of module
Implicit Euler scheme
Coming next
Numerical integration of partial
differential equations
68/78
Numerical integration of partial
differential equations
69/78
The diffusion equation
70/78
The diffusion equation: space discretization
71/78
The diffusion equation: space discretization
The Taylor expansion of Ci+1 and Ci−1 to second order reads
∂Ci ∆x2 ∂ 2 Ci
Ci+1 = Ci + ∆x + ,
∂x 2 ∂x2
∂Ci ∆x2 ∂ 2 Ci
Ci−1 = Ci − ∆x + .
∂x 2 ∂x2
By summing these equations one gets (xi ∈ [x1 , ..., xM−1 ])
∂ 2 Ci Ci+1 − 2Ci + Ci−1
=
∂x2 ∆x2
72/78
The diffusion equation: space discretization
The discretization of the Laplacian leads to
∂Ci (t) Ci+1 (t) − 2Ci (t) + Ci−1 (t)
=D .
∂t ∆x2
By defining C(t) = (C(x0 , t), C(x1 , t), ..., C(xM , t))T and A as
1 0 0 0 · · · 0 Remark
1 −2 1 0 ··· 0
0 1 −2 1 ··· 0 • The first and last lines of A
A = ... .. .. .. .. ..
correspond to boundary
. . . . .
. .. ..
conditions.
.. . . 1 −2 1
0 ··· ··· ··· 0 1
73/78
The diffusion equation: time discretization
74/78
The diffusion equation: time discretization
75/78
Numerical example
0.8
C(x0 , ti ) = 0, C(xf , ti ) = 1, ∀ti .
0.6
For t → ∞ admits a stationary
0.4
solution.
0.2
0
0 0.2 0.4 0.6 0.8 1
76/78
Numerical example
1
∆t = ∆x = 0.1
0.9 explicit
0.8 implicit
0.7
sationary
0.6
0.5
C
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x
77/78
End of module
Numerical integration of partial
differential equations
End of Week 3
Thank you for your attention!
78/78