D Savostyanov@essex Ac Uk
D Savostyanov@essex Ac Uk
Dr Dmitry Savostyanov
d.savostyanov@essex.ac.uk
Learning objectives
▶ To introduce the modelling cycle
▶ To distinguish and compare analytic and numerical methods
▶ To introduce and develop accurate numerical methods for first–order ODEs
▶ To apply numerical techniques to solve higher–order ODEs and systems of ODEs
Further reading
▶ Cleve Moler, Numerical Computing with MATLAB Chapter 7
uk.mathworks.com/content/dam/mathworks/mathworks-dot-com/moler/odes.pdf
▶ Alfio Quarteroni et al, Scientific Computing with MATLAB and Octave Sections 8.3, 8.7-8.11
Mathematical modelling
y ▶ Idealistic — we use ideal concepts (like numbers and
y(0) functions) to describe real world objects.
▶ Simplistic — we start with simple assumptions about
the object of study, not with an attempt to describe it
precisely.
▶ Focused — we attempt to reproduce a specific
phenomenon, not all complex behaviour of the real
y(t) object.
All models are wrong, but some are useful.
y ′ (t) = −gt + c1 t2
y(t) = −g · + c2
2
▶ use the initial condition
▶ use the other initial condition
′
y (0) = 0 ⇒ −g · 0 + c1 = 0
02
⇒ c1 = 0 y(0) = y0 ⇒ −g · + c2 = y0
2
⇒ c2 = y0
gt2
y(t) = y0 −
2
▶ integrate directly
▶ multiply both part with the I.F.,
′
y (t) + αy(t) = −gt + c1
y ′ (t)eαt + αeαt y(t) = (αy0 − gt) eαt
| {z }
▶ use the initial conditions:
αt ′
y(t)e = αy0 eαt − gteαt
y ′ (0) + αy(0) = g · 0 + c1
0 + αy0 = c1
′
y (t) + αy(t) = αy0 − gt
Example 2 (continued)
y y Air–suspended fall
y0 ▶ Laws of physics → ODE
y2 m⃗ a = m⃗g − k⃗v
k
y ′′ (t) = −g − y ′ (t)
y3 m
′ k
y (t) = −gt − (y(t) − y0 )
| m {z }
y4 f(t,y)
⃗v
▶ ODE → numerical method
y(t + ∆t) − y(t)
≈ y ′ (t) = f(t, y(t))
∆t
y(t + ∆t) ≈ y(t) + ∆t · f(t, y(t))
t
yn+1 = yn + h · f(tn , yn )
y(tn+1 ) − y(tn )
≈ y ′ (tn ) = f(tn , y(tn ))
tn+1 − tn y(t2 )
y2
▶ replace approximate equations with exact ones
yn+1 − yn
= f(tn , yn ) y3
tn+1 − tn y(t3 )
Accuracy analysis
y1 = y0 + f(t0 , y0 )h y3
y(t3 )
▶ Accuracy of one step is |y1 − y(t1 )| ≲ O(h2 )
▶ After N steps, |yN − y(tN )| ≲ NO(h2 ) = Th = O(h) t
0 h 2h 3h 4h
▶ k1 = f(t0 , y0 )
▶ k2 = f(t0 +h, y0 +hk1 ) = f(t0 , y0 )+ ∂f
∂t h+ ∂f
∂y hk1 +O(h2 ) t
t=t0 t=t0 0 h
Finally, y(t1 ) = y0 + k1 h + 12 (k2 − k1 )h +O(h3 ), so |y1 − y(t1 )| ≲ O(h3 )
| {z } |yN − y(tN )| ≲ O(h2 )
y1
Dmitry Savostyanov University of Essex 29th Jan 2024
MA209 Part 2 Heun’s methods 12 / 21
k1 h = c1 k1 h + c2 k1 h
c1 + c2 =1
a =b t
0 h
1 2
2h = c2 ah2 ⇔ c2 a = 12 ⇔ c1 =1− 1
1
2a
2 k1 h
2
= c2 bk1 h2 c2 b = 12 c2 1
= 2a
Dmitry Savostyanov University of Essex 29th Jan 2024
MA209 Part 2 Runge–Kutta methods 13 / 21
Error estimate: e1 = |y1 − y(t1 )| < |y1 − z2 | + |z2 − y(t1 )| ≃ 2|y1 − z2 | = ẽ1
| {z } | {z } | {z } t
0 h h
≲O(h3 ) ≲O(h2 ) ≲O(h2 ) 2
If ẽ1 is large, reduce h and repeat the step. If ẽ1 is small, increase h and continue.
Dmitry Savostyanov University of Essex 29th Jan 2024
MA209 Part 2 Adaptive choice of step–size 15 / 21
y1 = y0 + f(t0 , y0 )h +O(h2 )
▶ Euler’s method:
3
xn+1 = xn + (axn − bxn yn )h,
yn+1 = yn + (−cyn + dxn yn )h. 2
▶ Differential equations
5
x ′ (t) = ax − bxy, x(0) = x0 ,
y ′ (t) = −cy + dxy, y(0) = y0 . 4
▶ Euler’s method:
3
xn+1 = xn + (axn − bxn yn )h,
yn+1 = yn + (−cyn + dxn yn )h.
2
▶ Matlab code snippet:
for n=1:N 1
x(n+1)=x(n)+( a*x(n) -c*x(n)*y(n))*h;
y(n+1)=y(n)+(-b*y(n) +d*x(n)*y(n))*h;
end
x
1 2 3 4 5
Dmitry Savostyanov University of Essex 29th Jan 2024
MA209 Part 2 Systems of ODEs 20 / 21
Higher–order ODEs y
▶ Differential equations y0 y1
y ′′ (t) = −g − αy ′ (t), v ′ (t) = −g − αv(t), y(t1 )
⇒
y ′ (t) = v(t), y ′ (t) = v(t).