


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
PROTOTYPE INITIAL VALUE PROBLEM. 19 solve the ODE exactly if ∫ f(t) dt can be evaluated. We expect that the solution to the differential equation (2.2a) is ...
Typology: Slides
1 / 34
This page cannot be seen from the preview
Don't miss anything!



























The purpose of this chapter is to study the simplest numerical methods for ap- proximating the solution to a first order initial value problem (IVP). Because the methods are simple, we can easily derive them plus give graphical interpretations to gain intuition about our approximations. Once we analyze the errors made in replacing the continuous differential equation by a difference equation, we will see that the methods only converge linearly which is quite slow. This is the motivation for looking at higher accurate methods in the next chapter. We will look at several numerical examples and verify the linear convergence of the methods and we will see that in certain situations one of the methods tends to oscillate and even“blow up” while the other always provides reliable results. This will motivate us to study the numerical stability of methods. We begin by looking at the prototype IVP that we consider in this chapter and the next. The differential equation for this IVP is first order and gives information on the rate of change of our unknown; in addition, an initial value for the unknown is specified. Later, in Chapter 4, we consider higher order IVPs and we will see that higher order IVPs can be written as a system of first order IVPs so that all the methods we study in this chapter and the next can be easily extended to systems. Before we investigate methods to approximate the solution of this prototype IVP we consider conditions which guarantee that the analytic solution exists, is unique and depends continuously on the data. In the sequel we will only be interested in approximating the solution to such problems. Once we have specified our prototype IVP we introduce the idea of approximating its solution using a difference equation. In general, we have to give up the notion of finding an analytic solution which gives an expression for the solution at any time and instead find a discrete solution which is an approximation to the exact solution at a set of finite times. The basic idea is that we discretize our domain, in this case a time interval, and then derive a difference equation which approximates
the differential equation in some sense. The difference equation is in terms of a discrete function and only involves differences in the function values; that is, it does not contain any derivatives. Our hope is that as the difference equation is imposed at more and more points (which much be chosen in a uniform manner) then its solution will approach the exact solution to the IVP. The simplest methods for approximating the solution to our prototype IVP are the forward and backward Euler methods which we derive by approximating the derivative in the differential equation at a point by the slope of a secant line. In § 2.2.2 we demonstrate the linear convergence of the method by introducing the concepts of local truncation error and global error. The important differences in explicit and implicit methods are illustrated by comparing these two Euler methods. In § 2.3 we present some models of growth/decay which fit into our prototype IVP and give results of numerical simulations for specific problems. In addition, we demonstrate that our numerical rate of convergence matches our theoretical rate. Lastly, we demonstrate numerically that the forward Euler method gives unre- liable results in certain situations whereas the backward Euler always appears to give reliable results. This leads us to introduce the concept of numerical instability and to see why this is required for a numerical simulation to converge to the exact solution.
A problem commonly encountered is an initial value problem where we seek a func- tion whose value is known at some initial time and whose derivative is specified for subsequent times. The following problems are examples of first order IVPs for y(t):
{ (^) y′(t) = sin πt 0 < t ≤ 4 y(0) = 0.
{ (^) y′(t) + y (^2) (t) = t 2 < t ≤ 10 y(2) = 1. (2.1) Clearly, these examples are special cases of the following general IVP.
General IVP: find y(t) satisfying
dy dt
= f (t, y) t 0 < t ≤ T (2.2a)
y(t 0 ) = y 0. (2.2b)
Here f (t, y) is the given derivative of y(t) and y 0 is the known value at the initial time t 0. For example, for the IVP II in (2.1) we have f (t, y) = t − y^2 , t 0 = 2, T = 10 and y 0 = 1. Note that both linear and nonlinear differential equations are included in the general equation (2.2a). For certain choices of f (t, y) we can find an analytic solution to (2.2). In the simple case when f = f (t), i.e., f is a function of t and not both t and y, we can
We can always verify that we haven’t made an error in determining the solution by demon- strating that it satisfies the differential equation. Here we have
y(t) = Ce−^
t 22 ⇒ y′(t) = C − 2 t 2 e−^
t 22 = −t
( Ce−^
t 22 ) = −ty(t)
so the equation is satisfied. To determine a unique solution we impose the value of y(t) at some point; here we set y(0) = 2 to get the particular solution y(t) = 2e−t (^2) / 2 because
y(0) = 2, y(t) = Ce−^
t 22 ⇒ 2 = Ce^0 ⇒ C = 2.
Even if we are unable to determine the analytic solution to (2.2), we can still gain some qualitative understanding of the behavior of the solution. This is done by the visualization technique of plotting the tangent line to the solution at numerous points (t, y); recall that the slope of the tangent line to the solution curve is given and is just f (t, y). Mathematical software with graphical capabilities often provide commands for automatically drawing a direction field with arrows which are scaled to indicate the magnitude of the slope; typically they also offer the option of drawing some solutions or streamlines. Using direction fields to determine the behavior of the solution is illustrated in the following example.
Example 2.2. Direction fields
Draw the direction fields for the ODE
y′(t) = t^2 + y(t) 0 < t < 4
and indicate the specific solution which satisfies y(0) = 1. At each point (t, y) we draw the line with slope t^2 + y; this is illustrated in the figure below where numerous streamlines have been sketched. To thread a solution through the direction field start at a point and follow the solution, remembering that solutions don’t cross and that nearby tangent lines should be nearly the same. To see which streamline corresponds to the solution with y(0) = 1 we locate the point (0, 1) and follow the tangents; this solution is indicated by a thick line in the direction field plot below. If a different initial condition is imposed, then we get a different streamline.
2
4
Before we discuss methods for approximating the solution of the IVP (2.2) we first need to ask ourselves if our prototype IVP actually has an analytic solution, even if we are unable to find it. We are only interested in approximating the solution to IVPs which have a unique solution. However, even if we know that a unique solution exists, we may still have unreliable numerical results if the solution of the IVP does not depend continuously on the data. If this is the case, then small changes in the data can cause large changes in the solution and thus roundoff errors in our calculations can produce meaningless results. In this situation we say the IVP is ill- posed or ill-conditioned, a situation we would like to avoid. Luckily, most differential equations that arise from modeling real-world phenomena are well-posed. The conditions that guarantee well-posedness of a solution to (2.2) are well known and are presented in Theorem 2.1. Basically the theorem requires that the derivative of y(t) (given by f (t, y)) be continuous and, moreover, this derivative is not allowed to change too quickly as y changes. A basic problem in calculus is to determine how much a continuous function changes as the independent variables change; clearly we would like a function to change a small amount as an independent variable changes but this is not always the case. The concept of Lipschitz continuity 1 gives a precise measure of this “degree of continuity”. To understand this concept first think of a linear function g(x) = ax + b and consider the effect changing x has on the dependent variable g(x). We have
|g(x 1 ) − g(x 2 )| = |ax 1 + b − (ax 2 + b)| = |a| |x 1 − x 2 |.
This says that as the independent variable x varies from x 1 to x 2 the change in the dependent variable g is governed by the slope of the line, i.e., a = g′(x). For a general function g(x) Lipschitz continuity on an interval I requires that the magnitude of the slope of the line joining any two points x 1 and x 2 in I must be bounded by a real number. Formally, a function g(x) defined on a domain D ⊂ R^1 is Lipschitz continuous on D if for any x 1 6 = x 2 ∈ D there is a constant L such that |g(x 1 ) − g(x 2 )| ≤ L|x 1 − x 2 | ,
or equivalently |g(x 1 ) − g(x 2 )| |x 1 − x 2 |
Here L is called the Lipschitz constant. This condition says that we must find one constant L which works for all points in the domain. Clearly the Lipschitz constant is not unique; for example, if L = 5, then L = 5. 1 , 6 , 10 , 100 , etc. also satisfy the condition. If g(x) is differentiable then an easy way to determine the Lipschitz constant is to find a constant such that |g′(x)| ≤ L for all x ∈ D. The linear function g(x) = ax + b is Lipschitz continuous with L = |a| = |g′(x)|. Lipschitz continuity is a stronger condition than merely saying the function is continuous so a Lipschitz continuous function is always continuous but the converse is not true. For example, the function g(x) =
x is continuous on D = [0, 1] but is not Lipschitz continuous on D because g′(x) = 1/(
x) is not bounded on [0, 1]. (^1) Named after the German mathematician Rudolf Lipschitz (1832-1903).
the solution where we give up finding a formula for the solution at all times and instead find an approximation at a set of distinct times. Probably the most obvious approach to discretizing a differential equation is to approximate the derivatives in the equation by difference quotients to obtain a difference equation which involves only differences in function values. The solution to the difference equation will not be a continuous function but rather a discrete function which is defined over a finite set of points. When plotting the discrete solution one often draws a line through the points to get a continuous curve but remember that interpolation must be used to determine the solution at points other than grid points. In this chapter we concentrate on two of the simplest difference equations for (2.2a). Because the difference equation is defined at a finite set of points we first discretize the time domain [t 0 , T ]; alternately, if our solution depended on the spatial domain x instead of t we would discretize the given spatial interval. For now we use N + 1 evenly spaced points tn, n = 0, 1 , 2 ,... , N
t 1 = t 0 + ∆t, t 2 = t 0 + 2∆t, · · · , tN = t 0 + N ∆t = T ,
where ∆t = (T − t 0 )/N is called the step size or time step. Our task is to find a means for approximating the solution at each of these discrete values and our hope is that as we perform more calculations with N getting large, or equivalently ∆t → 0 , our approximate solution will approach the exact solution in some sense. In the left plot in Figure 2.1 we plot an exact solution (the continuous curve) to a specific IVP and a discrete approximation for ∆t =
We will see that there are many approaches to deriving discrete methods for our IVP (2.2) but the two simplest methods use the slope of a secant line to approximate the derivative in (2.2a). These methods are called the forward and backward Euler methods named after Leonhard Euler.^2 The methods can be derived from several different viewpoints but here we use the secant line approximation
y′(t) ≈
y(tn+1) − y(tn) ∆t
for t ∈ [tn, tn+1]. (2.4)
(^2) Euler (1707-1783) was a Swiss mathematician and physicist.
1 2 3 4
Ê
Ê Ê (^) Ê (^) Ê Ê^ Ê
Ê
Ê
‡ ‡ ‡ ‡ ‡ ‡ (^) ‡ (^) ‡ ‡ (^) ‡ ‡ (^) ‡ (^) ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡^ ‡^ ‡^
‡ ‡^
‡^ ‡
‡^ ‡
‡ ‡
‡ ‡
‡
Ï Ï Ï Ï Ï Ï ÏÏÏÏ ÏÏÏÏÏÏ ÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏÏ
ÏÏÏÏ ÏÏÏ Ï^ Ï^ Ï
Ï^ Ï Ï^ Ï Ï^ Ï
Ï^ Ï
Ï^ Ï
Ï^ Ï
Ú Ú Ú Ú Ú (^) Ú (^) Ú Ú Ú Ú Ú^ Ú
Ú Ú
Ú
Ú
Ú
1 2 3 4
Figure 2.1: The exact solution to an IVP is shown as a solid curve. In the figure on the left a discrete solution using ∆t = 0. 5 is plotted. From this plot, it is not possible to say that the discrete solution is approaching the exact solution. However, in the figure on the right the discrete solutions for ∆t = 0. 5 , 0. 25 , 0. 125 , and 0. are plotted. From this figure, the discrete approximations appear to be approaching the exact solution as ∆t decreases.
Using this difference quotient to approximate y′(tn) gives one method and using it to approximate y′(tn+1) gives the other method. When we write a difference equation we need to use different notation for the exact solution y(t) and its discrete approximation; to this end, we let Y n^ denote the approximation to y(tn). Clearly Y 0 = y 0 which is the given initial condition (2.2b). We now want to write a difference equation which will allow us to calculate Y 1 ≈ y(t 1 ). We use the differential equation evaluated at t 0 , i.e., y′(t 0 ) = f (t 0 , y 0 ), and the approximation for y′(t 0 ) from (2.4) with n = 0 and t = t 0 , i.e., y′(t 0 ) ≈ (Y 1 − Y 0 )/∆t, to get the difference equation
Y 1 − Y 0 ∆t
= f (t 0 , Y 0 ).
We have a starting point Y 0 = y 0 from our initial condition and thus we can solve for our approximation to y(t 1 ) from
Y 1 = Y 0 + ∆tf (t 0 , Y 0 ). (2.5)
Once Y 1 is obtained we can repeat the process to obtain a difference equation for Y 2. This procedure is known as the forward Euler method and is defined by the following formula.
Forward Euler: Y n+1^ = Y n^ + ∆tf (tn, Y n) , n = 0, 1 , 2 ,... , N − 1 (2.6)
The term “forward” is used in the name because we write the equation at the point tn and difference forward in time to tn+1; note that this implies that the given slope f is evaluated at the known point (tn, Y n).
leads to the difference equation
Y 1 − Y 0 ∆t
= f (t 1 , Y 1 ) ⇒ Y 1 = Y 0 + ∆tf (t 1 , Y 1 ).
It is important to realize that this equation is inherently different from (2.5) because we must evaluate f (t, y) at the unknown point (t 1 , Y 1 ). In general, this leads to a nonlinear equation to solve for each Y n^ which can be computationally expensive. For example, if we have f (t, y) = ety^ then the equation for Y 1 is
Y 1 = Y 0 + ∆tet^1 Y^
1
which is a nonlinear equation for the unknown Y 1. This method is called the back- ward Euler method because we are writing the equation at tn+1 and differencing backwards in time to tn.
Backward Euler: Y n+1^ = Y n^ + ∆tf (tn+1, Y n+1) , n = 0, 1 , 2 ,... , N − 1 (2.7)
The difference between the forward and backward Euler schemes is so impor- tant that we use this characteristic to broadly classify methods. The forward Euler scheme given in (2.6) is called an explicit scheme because we can write the un- known explicitly in terms of known values. The backward Euler method given in (2.7) is called an implicit scheme because the unknown is written implicitly in terms of known values and itself. The terms explicit/implicit are used in the same manner as explicit/implicit differentiation. In explicit differentiation a function to be differentiated is given explicitly in terms of the independent variable such as y(t) = t^3 + sec t; in implicit differentiation the function is given implicitly such as y^2 + sin y − t^2 = 4 and we want to compute y′(t). In the exercises you will get practice in identifying schemes as explicit or implicit. In the case when f (t, y) is linear in y we can get a general formula for Y n^ in terms of Y 0 and ∆t for both the forward and backward Euler methods by applying the formulas recursively. This means that we can compute an approximation to y(tn) without computing approximations at y(tn− 1 ),... , y(t 1 ) which we normally have to do. The following example illustrates this for the forward Euler method and in the exercises you are asked to find the analogous formula for the backward Euler method. In the next example we fix the time step and compare the relative error for a range of final times; in Exercise 2.5 we fix the final time and reduce the time step.
Example 2.3. General solution to forward euler difference equation for lin- ear equations
Consider the IVP y′(t) = −λy 0 < t ≤ T, y(0) = y 0
whose exact solution is y(t) = y 0 e−λt. Find the general solution for Y n^ in terms of Y 0 and ∆t for the forward Euler method.
For the forward Euler method we have
Y 1 = Y 0 + ∆t(−λY 0 ) = (1 − λ∆t)Y 0.
Similarly Y 2 = (1 − λ∆t)Y 1 = (1 − λ∆t)^2 Y 0
Continuing in this manner gives
Y n^ = (1 − λ∆t)nY 0.
Example 2.4. Error in the forward euler method for fixed time
In this example, we fix the time step ∆t and compare the relative error for a range of times using the formula in Example 2.3. Set λ = 5, y 0 = 2 and ∆t = 1/ 20 in Example 2.3 and compute the relative error at t = 0. 2 , 0. 4 ,... , 1. 0.
For this choice of ∆t and λ the forward Euler formula we derived in Example 2.3 reduces to Y n^ = 2(0. 95 n). We give the relative error as a percent; it is computed by taking the actual error, normalizing by the exact solution and converting to a percent. The table below gives the approximations.
t Percentage Error
0.2 2.55% 0.4 5.04% 0.6 7.47% 0.8 9.83% 1.0 12.1%
As can be seen from the table the relative error increases as the time increases which we expect because the errors are being accumulated; this will be discussed in detail in the next section. It is important to compute a relative error because if the exact solution is near zero then the absolute error may be small while the relative error is large.
Example 2.5. Error in the forward euler method as time step decreases
In this example we fix the time at which the error is calculated and vary ∆t using the formula derived in Example 2.3 for the forward Euler method with λ = 5 and y 0 = 2. We compute the absolute and relative errors at t = 1 for ∆t = 1/ 10 ,... , 1 / 320 and discuss the results. Then we determine how many times do have to halve the time step if we want the relative error to be less than 1%.
We use the expressions for Y n^ from Example 2.3 to determine the approximations to y(1) = 2e−^5 ≈ 1 .3476 10−^2.
t t 0 t 1 t 2 t 3
y(t)
s Y 0 = y(t 0 )
Y 1 s
Y (^) s 2