Error Analysis
Error Analysis
Euler’s Method
Improved Euler’s Method
Joseph M. Mahaffy,
[email protected]
Spring 2022
Lecture Notes – Numerical Methods for Differe
Joseph M. Mahaffy, [email protected] — (1/39)
Introduction
Euler’s Method
Improved Euler’s Method
Outline
1 Introduction
2 Euler’s Method
Malthusian Growth Example
Euler’s Method - MatLab
Example with f (t, y)
Euler Error Analysis
Introduction
Introduction
Euler’s Method 1
Initial Value Problem: Consider
dy
= f (t, y) with y(t0 ) = y0
dt
Euler’s Method 2
Euler’s Method for a fixed h is
Euler’s Method 3
Euler’s Method
(t ,y ) (t3,y3) y(t)
2 2
(t ,y ) (t ,y )
(t1,y1) 4 4 n+1 n+1
(tn,yn)
y0
h
t0 t1 t2 t3 t4 tn tn+1
Euler’s Method 4
Euler’s Method Formula: Euler’s method is just a discrete
dynamical system for approximating the solution of a continuous
model
Let tn+1 = tn + h
Define yn = y(tn )
The initial condition gives y(t0 ) = y0
Euler’s Method is the discrete dynamical system
yn+1 = yn + h f (tn , yn )
Euler’s Method only needs the initial condition to start and the
right hand side of the differential equation (the slope field),
f (t, y) to obtain the approximate solution
P (t) = 50 e0.2t
Pn+1 = Pn + h 0.2 Pn
tn Pn
t0 = 0 P0 = 50
t1 = t0 + h = 0.1 P1 = P0 + 0.1(0.2P0 ) = 50 + 1 = 51
t2 = t1 + h = 0.2 P2 = P1 + 0.1(0.2P1 ) = 51 + 1.02 = 52.02
t3 = t2 + h = 0.3 P3 = P2 + 0.1(0.2P2 ) = 52.02 + 1.0404 = 53.0604
Euler’s Method
60 Actual Solution
58
56
P(t)
54
52
50
0 0.2 0.4 0.6 0.8 1
350
300
250
P (t)
200
150
100
50
Actual Solution
Euler h = 0.5
Euler h = 0.25
0
0 1 2 3 4 5 6 7 8 9 10
t
yn+1 = yn + hf (tn , yn ).
yn+1 = yn + 0.25(yn + tn )
tn Euler solution yn
t0 = 0 y0 = 3
t1 = 0.25 y1 = y0 + h(y0 + t0 ) = 3 + 0.25(3 + 0) = 3.75
t2 = 0.5 y2 = y1 + h(y1 + t1 ) = 3.75 + 0.25(3.75 + 0.25) = 4.75
t3 = 0.75 y3 = y2 + h(y2 + t2 ) = 4.75 + 0.25(4.75 + 0.5) = 6.0624
t4 = 1 y4 = y3 + h(y3 + t3 ) = 6.0624 + 0.25(6.0624 + 0.75) = 7.7656
yn+1 = yn + h(yn + tn )
M h2 p
≤ε or h≤ 2ε/M
2
Often difficult to estimate either |φ00 (t)| or M
Lecture Notes – Numerical Methods for Differe
Joseph M. Mahaffy, [email protected] — (22/39)
Malthusian Growth Example
Introduction
Euler’s Method - MatLab
Euler’s Method
Example with f (t, y)
Improved Euler’s Method
Euler Error Analysis
Global Truncation
Other Errors
The local truncation error satisfies |en | ≤ M h2 /2
This error is most significant for adaptive numerical
routines where code is created to maintain a certain
tolerance
Global Truncation Error
The more important error for the numerical routines is this
error over the entire simulation
Euler’s method can be shown to have a global
truncation error,
|En | ≤ Kh
Note error is one order less than local error, which scales
proportionally with the stepsize or |En | ≤ O(h)
HW problem using Taylor’s series and Math induction to
prove this result
Lecture Notes – Numerical Methods for Differe
Joseph M. Mahaffy, [email protected] — (23/39)
Malthusian Growth Example
Introduction
Euler’s Method - MatLab
Euler’s Method
Example with f (t, y)
Improved Euler’s Method
Euler Error Analysis
yen = yn + hf (tn , yn )
y(t) = 4 et − t − 1
with
h
yn+1 = yn + 2 ((yn + tn ) + (yen + tn + h))
yn+1 = yn + 0.05 (yn + yen + 2 tn + 0.1)
25
20
y(t)
15
10
Actual Solution
Euler Solution
Improved Euler
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t
Numerical Example 1
Numerical Example 2
dy
Numerical Solution for dt = 2e−0.1t − sin(y), y(0) = 3
Used MatLab’s ode45 to obtain an accurate numerical solution to
compare Euler’s method and Improved Euler’s method with
stepsizes h = 0.2, h = 0.1, and h = 0.05
“Actual” Euler Im Eul Euler Im Eul Euler Im Eul
tn h = 0.2 h = 0.2 h = 0.1 h = 0.1 h = 0.05 h = 0.05
0 3 3 3 3 3 3 3
1 5.5415 5.4455 5.5206 5.4981 5.5361 5.5209 5.5401
2 7.1032 7.1718 7.0881 7.1368 7.0995 7.1199 7.1023
3 7.753 7.836 7.743 7.7939 7.7505 7.7734 7.7524
4 8.1774 8.2818 8.167 8.2288 8.1748 8.2029 8.1768
5 8.5941 8.7558 8.5774 8.6737 8.5899 8.6336 8.5931
1.88% −0.194% 0.926% −0.0489% 0.460% −0.0116%
Numerical Example 3
Numerical Example 4
Graph of Solution: Actual, Euler’s and Improved Euler’s methods
with h = 0.2
dy/dt = y + t
30
25
20
y(t)
15
10
Actual Solution
Euler Solution
Improved Euler
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
t
Order of Error
Error of Numerical Solutions
Order of Error without good “Actual solution”
Simulate system with stepsizes h, h/2, and h/4 and define
these simulates as yn1 , yn2 , and yn3 , respectively
Compute the ratio (from Cauchy sequence)
|yn3 − yn2 |
R=
|yn2 − yn1 |