





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Math 246, Spring 2009, Professor Levermore Numerical Methods
For many first order differential equations analytic methods are either difficult or impossible to apply. If one is interested in understanding how a particular solution behaves it is often easiest to use numerical methods to construct accurate approximations to the solution. Suppose we are interested in the solution Y (t) of the initial-value problem
dy dt
= f (t, y) , y(tI ) = yI , (1.1)
over the time interval [tI , tF ] — i.e. for tI ≤ t ≤ tF. Here tI is called the initial time and tF is called the final time. A numerical method selects times {tn}Nn=0 such that
tI = t 0 < t 1 < t 2 < · · · < tN− 1 < tN = tF ,
and computes values {yn}Nn=0 such that y 0 = Y (t 0 ) = yI and yn approximates Y (tn) for n = 1, 2 , · · · , N. For good numerical methods, these approximations will improve as N increases. So for sufficiently large N you can plot the points {(tn, yn)}Nn=0 in the (t, y)- plane and “connect the dots” to get an accurate picture of how Y (t) behaves over the time interval [tI , tF ].
Here we will introduce a few basic numerical methods in simple settings. The numer- ical methods used in software packages such as MATLAB are generally far more sophisti- cated than those we will study here. They are however built upon the same fundamental ideas as the simpler methods we will study. Throughout this section we will make the following two basic simplifications.
h =
tF − tI N
, and tn = tI + nh for n = 0, 1 , · · · , N , (1.2)
where h is called the time step.
Sophisticated software packages use methods in which the time step is chosen adaptively. In other words, the choice of tn+1 will depend on the behavior of recent approximations — for example, on (tn, yn) and (tn− 1 , yn− 1 ). Employing uniform time steps will greatly simplify the algorithms, and thereby simplify the programming you will have to do. If you do not like the way a run looks, you will simply try again with a larger N. Similarly, sophisticated software packages will sometimes use so-called multi-step methods for which the value of yn+1 for n = m, m + 1, · · · , N − 1 will depend on yn, yn− 1 , · · · , and yn−m for some positive integer m. Employing one-step methods will again simplify the algorithms, and thereby simplify the programming you will have to do. 1
1.1. Euler Methods. The simplest (and the least accurate) numerical methods are the Euler methods. These can be derived many ways. Here we give a simple approach (not taken in class) based on the definition of the derivative through difference quotients.
If we start with the fact that
lim h→ 0
Y (t + h) − Y (t) h
dY dt
(t) = f (t, Y (t)) ,
then for small positive h one has
Y (t + h) − Y (t) h
≈ f (t, Y (t)).
Upon solving this for Y (t + h) we find that
Y (t + h) ≈ Y (t) + hf (t, Y (t)).
If we let t = tn above (so that t + h = tn+1) this is equivalent to
Y (tn+1) ≈ Y (tn) + hf (tn, Y (tn)).
Because yn and yn+1 are approximations of Y (tn) and Y (tn+1) respectively, this suggests setting yn+1 = yn + hf (tn, yn) for n = 0, 1 , · · · , N − 1. (1.3)
This so-called Euler method was introduced by Euler in 1700’s.
Alternatively, we could have start with the fact that
lim h→ 0
Y (t) − Y (t − h) h
dY dt
(t) = f (t, Y (t)) ,
then for small positive h one has
Y (t) − Y (t − h) h
≈ f (t, Y (t)).
Upon solving this for Y (t − h) we find that
Y (t − h) ≈ Y (t) − hf (t, Y (t)).
If we let t = tn+1 above (so that t − h = tn) this is equivalent to
Y (tn+1) − hf (tn+1, Y (tn+1)) ≈ Y (tn).
Because yn and yn+1 are approximations of Y (tn) and Y (tn+1) respectively, this suggests setting yn+1 − hf (tn+1, yn+1) = yn for n = 0, 1 , · · · , N − 1. (1.4)
behaves as you increase N , the number of time steps — or what is equivalent by (1.2), as you decrease h, the time step. The O(h^2 ) term in (1.5) represents the local error, which is error the approximation makes at each step. Roughly speaking, if you halve the time step h then by (1.5) the local error will reduce by a factor of four while by (1.2) the number of steps N you must take to get to a prescribed time (say tF ) will double. If we assume that the errors add (which is often the case) then the error at tF will reduce by a factor of two. In other words, doubling the number of time steps will reduce the error by about a factor of two. Similarly, tripling the number of time steps will reduce the error by about a factor of three. Indeed, one can show (but we will not do so) that the error of the explicit Euler method is O(h) over the interval [tI , tF ]. The best way to think about this is that if you take N steps and the error made at each step is O(h^2 ) then you can expect that the acummulation of the local errors will lead to a global error of O(h^2 )N. Because (1.2) states that hN = tF − tI , which is a fixed number that is independent of h and N , you thereby see that global error of the explicit Euler method is O(h). Moreover, the error of the implicit Euler method behaves the same way.
Because the global error tells you how fast a method converges over the entire interval [tI , tF ], it is a more meaningful concept than local error. We therefore identify the order of a method by the order of its global error. In particular, methods like the Euler methods with global errors of O(h) are first order methods. By the reasoning of the previous paragraph, methods whose local error is O(hm+1) will have a global error of O(hm+1)N = O(hm) and are thereby mth^ order methods.
Higher order methods are more complicated than the explicit Euler method. The hope is that this cost is overcome by the fact that its error improves faster as you increase N — or what is equivalent by (1.2), as you decrease h. For example, if you halve the time step h of a fourth order method then the global error will reduce by a factor of sixteen. Similarly, tripling the number of time steps will reduce the error by about a factor of 81.
1.2.3. A Second Order Explicit Method. The second order Taylor approximation states that if Y (t) is thrice continuously differentiable then
Y (t + h) = Y (t) + h
dY dt
(t) + 12 h^2
d^2 Y dt^2
(t) + O(h^3 ). (1.7)
Here the O(h^3 ) means that the remainder vanishes at least as fast as h^3 as h tends to zero.
It is clear from (1.7) that for small positive h one has
Y (t + h) ≈ Y (t) + h
dY dt
(t) + 12 h^2
d^2 Y dt^2
(t). (1.8)
Because Y (t) satisfies (1.1), we see that
d^2 Y dt^2
(t) =
d dt
dY dt
(t)
d dt
f (t, Y (t)) = ∂tf (t, Y (t)) +
dY dt
(t) ∂yf (t, Y (t))
= ∂tf (t, Y (t)) + f (t, Y (t)) ∂yf (t, Y (t)).
Hence, equation (1.8) is the same as
Y (t + h) ≈ Y (t) + hf (t, Y (t)) + 12 h^2
∂tf (t, Y (t)) + f (t, Y (t)) ∂yf (t, Y (t))
If we let t = tn above (so that t + h = tn+1) this is equivalent to
Y (tn+1) ≈ Y (tn) + hf (tn, Y (tn)) + 12 h^2
∂tf (tn, Y (tn)) + f (tn, Y (tn)) ∂yf (tn, Y (tn))
Because yn and yn+1 are approximations of Y (tn) and Y (tn+1) respectively, this suggests setting
yn+1 = yn + hf (tn, yn) + 12 h^2
∂tf (tn, yn) + f (tn, yn) ∂yf (tn, yn)
for n = 0, 1 , · · · , N − 1.
We call this the second-order Taylor-based method.
1.2.4. Higher Order Explicit Methods. By generalizing what we did in the last subsection, one can use the nth^ order Taylor approximation to derive an explicit numerical method whose error is O(hn) over the interval [to, tf ] — a so-called nth^ order method. However, the formulas for these methods grow in complexity. For example, the third order method is
yn+1 = yn + hf (tn, yn) + 12 h^2
∂tf (tn, yn) + f (tn, yn) ∂yf (tn, yn)
∂ttf (tn, yn) + 2f (tn, yn) ∂ytf (tn, yn) + f (tn, yn)^2 ∂yyf (tn, yn)
∂tf (tn, yn) + f (tn, yn) ∂yf (tn, yn)
∂xf (tn, yn)
for n = 0, 1 , · · · , N − 1.
This complexity makes them less practical for general algorithms than the next class of methods we will study.
1.3. Explicit Methods Based on Numerical Quadrature. The starting point for our next class of methods will be the Fundamental Theorem of Calculus — specifically, the fact that
Y (t + h) − Y (t) =
∫ (^) t+h
t
dY dt
(s) ds.
Because Y (t) satisfies (1.1), this becomes
Y (t + h) − Y (t) =
∫ (^) t+h
t
f (s, Y (s)) ds. (1.11)
The idea now is to replace the definite integral on the right-hand side above with a numer- ical approximation — a so-called numerical quadrature. In particular, we will employ four
1.3.2. Heun-Trapezoidal Method. The trapezoidal rule approximates the definite integral on the right-hand side of (1.11) as ∫ (^) t+h
t
f (s, Y (s)) ds =
h 2
f (t, Y (t)) + f (t + h, Y (t + h))
whereby you see that (1.11) becomes
Y (t + h) = Y (t) +
h 2
f (t, Y (t)) + f (t + h, Y (t + h))
If you approximate Y (t + h) by the forward Euler method then
Y (t + h) = Y (t) +
h 2
f (t, Y (t)) + f
t + h, Y (t) + hf (t, Y (t))
If we let t = tn above (so that t + h = tn+1) this is equivalent to
Y (tn+1) = Y (tn) +
h 2
f (tn, Y (tn)) + f
tn+1, Y (tn) + hf (tn, Y (tn))
Because yn and yn+1 approximate Y (tn) and Y (tn+1) respectively, this suggests setting
yn+1 = yn +
h 2
f (tn, yn) + f
tn+1, yn + hf (tn, yn)
for n = 0, 1 , · · · , N − 1.
The book calls this the Improved Euler method. That name is sometimes used for other methods. Moreover, it is not very descriptive. We will call it the Heun-Trapezoidal method, which makes its origins clearer. In practice, it is implemented by initializing y 0 = yI and then for n = 0, · · · , N − 1 cycling through the instructions
fn = f (tn, yn) , f^ ˜n+1 = f (tn+1, ˜yn+1) ,
y ˜n+1 = yn + hfn , yn+1 = yn + 12 h[fn + f˜n+1] ,
where tn = tI + nh.
Example. Let y(t) be the solution of the initial-value problem
dy dt
= t^2 + y^2 , y(0) = 1.
Use the Heun-Trapezoidal method with h = .2 to approximate y(.2).
Solution. We initialize t 0 = 0 and y 0 = 1. The Heun-Trapezoidal method then gives
f 0 = f (t 0 , y 0 ) = 0^2 + 1^2 = 1 ˜y 1 = y 0 + hf 0 = 1 +. 2 · 1 = 1. 2 f˜ 1 = f (t 1 , ˜y 1 ) = (.2)^2 + (1.2)^2 = .04 + 1.44 = 1. 48 y 1 = y 0 + 12 h
f 0 + f˜ 1
We then have y(.2) ≈ y 1 = 1.224.
1.3.3. Heun-Midpoint Method. The midpoint rule approximates the definite integral on the right-hand side of (1.11) as
∫ (^) t+h
t
f (s, Y (s)) ds = hf
t + 12 h, Y (t + 12 h)
whereby you see that (1.11) becomes
Y (t + h) = Y (t) + hf
t + 12 h, Y (t + 12 h)
If you approximate Y (t + 12 h) by the forward Euler method then
Y (t + h) = Y (t) + hf
t + 12 h, Y (t) + 12 hf (t, Y (t))
If we let t = tn above (so that t + h = tn+1) this is equivalent to
Y (tn+1) = Y (tn) + hf
tn+ 12 , Y (tn) + 12 hf (tn, Y (tn))
where tn+ 12 = tn + 12 h = tI + (n + 12 )h. Because yn and yn+1 approximate Y (tn) and
Y (tn+1) respectively, this suggests setting
yn+1 = yn + hf
tn+ 12 , yn + 12 hf (tn, yn)
for n = 0, 1 , · · · , N − 1.
This is called the Heun-Midpoint method. In practice, it is implemented by initializing y 0 = yI and then for n = 0, · · · , N − 1 cycling through the instructions
fn = f (tn, yn) , fn+ 12 = f (tn+ 12 , yn+ 12 ) ,
yn+ 12 = yn + 12 hfn , yn+1 = yn + hfn+ 12 ,
where tn = tI + nh and tn+ 12 = tI + (n + 12 )h.
Example. Let y(t) be the solution of the initial-value problem
dy dt
= t^2 + y^2 , y(0) = 1.
Use the Heun-Midpoint method with h = .2 to approximate y(.2).
Solution. We initialize t 0 = 0 and y 0 = 1. The Heun-Midpoint method then gives
f 0 = f (t 0 , y 0 ) = 0^2 + 1^2 = 1 y˜ 12 = y 0 + 12 hf 0 = 1 +. 1 · 1 = 1. 1
f˜ 1 2 =^ f^ (t^12 ,^ y˜^12 ) = (.1)
y 1 = y 0 + h f˜ 12 = 1 +. 2 · (1.22) = 1 + .244 = 1. 244
We then have y(.2) ≈ y 1 = 1.244.