0% found this document useful (0 votes)
44 views

Euler Method Review

Euler's numerical method approximates solutions to differential equations by sequentially computing tangent line approximations. It generates a numerical solution consisting of two lists of numbers that pair the independent and dependent variables at discrete points. The method works by iteratively calculating the next x- and y-values using the previous values and the derivative formula, building up a piecewise linear approximation to the solution curve over successive steps. The example problem solves the differential equation dy/dx = -x^2 - y^2 with initial condition y(0)=1, choosing a step size of 1/2 and computing up to x=3 in 6 steps.

Uploaded by

Untitled Song
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Euler Method Review

Euler's numerical method approximates solutions to differential equations by sequentially computing tangent line approximations. It generates a numerical solution consisting of two lists of numbers that pair the independent and dependent variables at discrete points. The method works by iteratively calculating the next x- and y-values using the previous values and the derivative formula, building up a piecewise linear approximation to the solution curve over successive steps. The example problem solves the differential equation dy/dx = -x^2 - y^2 with initial condition y(0)=1, choosing a step size of 1/2 and computing up to x=3 in 6 steps.

Uploaded by

Untitled Song
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

9

Euler’s Numerical Method

In the last chapter, we saw that a computer can easily generate a slope feld for a given frst-order
differential equation. Using that slope feld we can sketch a fair approximation to the graph
of the solution y to a given initial-value problem, and then, from that graph, we fnd fnd an
approximation to y(x) for any desired x in the region of the sketched slope feld. The obvious
question now arises: Why not let the computer do all the work and just tell us the approximate
value of y(x) for the desired x ?
Well, why not?
In this chapter, we will develop, use, and analyze one method for generating a “numerical
solution” to a frst-order differential equation. This type of “solution” is not a formula or equation
for the actual solution y(x) , but two lists of numbers,

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

with each yk approximating the value of y(xk ) . Obviously, a nice formula or equation for y(x)
would be usually be preferred over a list of approximate values, but, when obtaining that nice
formula or equation is not practical, a numerical solution is better than nothing.
The method we will study in this chapter is “Euler’s method”. It is but one of many methods
for generating numerical solutions to differential equations. We choose it as the frst numerical
method to study because is relatively simple, and, using it, you will be able to see many of the
advantages and the disadvantages of numerical solutions. Besides, most of the other methods
that might be discussed are refnements of Euler’s method, so we might as well learn this method
frst.

9.1 Deriving the Steps of the Method


Euler’s method is based on approximating the graph of a solution y(x) with a sequence of
tangent line approximations computed sequentially, in “steps”. Our frst task, then, is to derive a
useful formula for the tangent line approximation in each step.

191
192 Euler’s Numerical Method

Y y(x) Y (x 5 , y5 )
y(x k + 1x) Lk L5
y(x k ) + 1y
1y (x 4 , y4 )
L4
I
y(x k ) --------. L3
L2 (x 3 , y3 )
X L1 (x 1 , y1 ) (x 2 , y2 )
xk 1x x k + 1x y0
x0 X
(a) (b)

Figure 9.1: (a) A single tangent line approximation for the Euler method, and (b) the
approximation of the solution curve generated by fve steps of Euler’s method.

The Basic Step Approximation


Let y = y(x) be the desired solution to some frst-order differential equation
dy
= f (x, y) ,
dx
and let xk be some value for x on the interval of interest. As illustrated in fgure 9.1a, (xk , y(xk ))
is a point on the graph of y = y(x) , and the nearby points on this graph can be approximated
by corresponding points on the straight line tangent at point (xk , y(xk )) (line L k in fgure 9.1a).
As with the slope lines in the last chapter, the differential equation can give us the slope of this
line:
dy
the slope of the approximating line = at (xk , y(xk )) = f (xk , y(xk )) .
dx
Now let 1x be any positive distance in the X direction. Using our tangent line approxi-
mation (again, see fgure 9.1a), we have that
y(xk + 1x) ≈ y(xk ) + 1y
where
1y
= slope of the approximating line = f (xk , y(xk )) .
1x
So,
1y = 1x · f (xk , y(xk ))
and
y(xk + 1x) ≈ y(xk ) + 1x · f (xk , y(xk )) . (9.1)
Approximation (9.1) is the fundamental approximation underlying each basic step of Euler’s
method. However, in what follows, the value of y(xk ) will usually only be known by some
approximation yk . With this approximation, we have
y(xk ) + 1x · f (xk , y(xk )) ≈ yk + 1x · f (xk , yk ) ,
which, combined with approximation (9.1), yields the approximation that will actually be used
in Euler’s method,
y(xk + 1x) ≈ yk + 1x · f (xk , yk ) . (9.2)
The distance 1x in the above approximations is called the step size. We will see that
choosing a good value for the step size is important.
Computing Via Euler’s Method (Illustrated) 193

Generating the Numerical Solution (Generalities)


Euler’s method is used to solve frst-order initial-value problems. We start with the point (x0 , y0 )
where y0 = y(x0 ) is the initial data for the initial-value problem to be solved. Then, repeatedly
increasing x by some positive value 1x , and computing corresponding values of y using a
formula based on approximation (9.2), we will obtain those two sequences

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

with yk ≈ y(xk ) for each k . Plotting the (xk , yk ) points, and connecting the resulting dots with
short straight lines leads to a piecewise straight approximation to the graph of the solution y(x)
as illustrated in fgure 9.1b. For convenience, let us denote this approximation generated by the
Euler method by y E,1x .
As already indicated, N will denote the number of steps taken. It must be chosen along
with 1x to ensure that x N is the maximum value of x of interest. In theory, both N and the
maximum value of x can be infnite. In practice, they must be fnite.
The precise steps of Euler’s method are outlined and illustrated in the next section.

9.2 Computing Via Euler’s Method (Illustrated)


Suppose we wish to fnd a numerical solution to some frst-order differential equation with initial
data y(x0 ) = y0 , say,
dy
5 − y 2 = −x 2 with y(0) = 1 . (9.3)
dx
(As it turns out, this differential equation is not easily solved by any of the methods already
discussed. So if we want to fnd the value of, say, y(3) , then a numerical method may be our
only choice.)
To use Euler’s method to fnd our numerical solution, we follow the steps given below.
These steps are grouped into two parts: the main part in which the values of the xk ’s and yk ’s
are iteratively computed, and the preliminary part in which the constants and formulas for those
iterative computations are determined.

The Steps in Euler’s Method


Part I (Preliminaries)
1. Get the differential equation into derivative formula form,
dy
= f (x, y) .
dx
For our example, solving for the derivative formula form yields
dy 1 2
y − x2

= .
dx 5

2. Set x0 and y0 equal to the x and y values of the initial data.


194 Euler’s Numerical Method

In our example, the initial data is y(0) = 1 . So

x0 = 0 and y0 = 1 .

3. Pick a distance 1x for the step size, a positive integer N for the maximum number of
steps, and a maximum value desired for x , x max . These quantities should be chosen so
that
xmax = x0 + N 1x .
Of course, you only choose two of these values, and compute the third. Which two are
chosen depends on the problem.
For no good reason whatsoever, let us pick
1
1x = and N = 6 .
2
Then
1
xmax = x0 + N 1x = 0 + 6 · = 3 .
2
4. Write out the equations

xk+1 = xk + 1x (9.4a)
and
yk+1 = yk + 1x · f (xk , yk ) (9.4b)

using the information from the previous steps.


For our example,
1 2 1
y − x2

f (x, y) = and 1x = .
5 2
So, for our example, equation set (9.4) becomes
1
xk+1 = xk + (9.4a ′ )
2
and
1 1 2
· y − x2

yk+1 = yk +
2 5
1 2
yk − xk 2 . (9.4b ′ )

= yk +
10

Formula (9.4b) for yk+1 is based on approximation (9.2). According to that approximation,
if y(x) is the solution to our initial-value problem and yk ≈ y(xk ) , then

y(xk+1 ) = y(xk + 1x) ≈ yk + 1x · f (xk , yk ) = yk+1 .

Because of this, each yk generated by Euler’s method is an approximation of y(xk ) .


Computing Via Euler’s Method (Illustrated) 195

Part II of Euler’s Method (Iterative Computations)


1. Compute x1 and y1 using equation set (9.4) with k = 0 and the values of x0 and y0
from the initial data.
For our example, using equation set (9.4 ′ ) with k = 0 and the initial values
x0 = 0 and y0 = 1 gives us
1 1
x1 = x0+1 = x0 + 1x = 0 + = ,
2 2
and
y1 = y0+1 = y0 + 1x · f (x0 , y0 )
1 2
y0 − x0 2

= y0 +
10
1 2 11
1 − 02 =

= 1 + .
10 10

2. Compute x2 and y2 using equation set (9.4) with k = 1 and the values of x1 and y1
from the previous step.
For our example, equation set (9.4 ′ ) with k = 1 and the above values for x1
and y1 yields
1 1
x2 = x1+1 = x1 + 1x = + = 1 ,
2 2
and
y2 = y1+1 = y1 + 1x · f (x1 , y1 )
1 2
y1 − x1 2

= y1 +
10
"   2 #
2
11 1 11 1 290
= + − = .
10 10 10 2 250

3. Compute x3 and y3 using equation set (9.4) with k = 2 and the values of x2 and y2
from the previous step.
For our example, equation set (9.4 ′ ) with k = 2 and the above values for x2
and y2 yields
1 3
x3 = x2+1 = x2 + 1x = 1 + = ,
2 2
and
1 2
y2 − x2 2

y3 = y2+1 = y2 +
10
" 2 #
29 1 29 774,401
= + − 12 = .
250 10 250 625,000

For future convenience, note that


774,401
y3 = ≈ 1.2390 .
625,000
196 Euler’s Numerical Method

(d), (e), … In each subsequent step, increase k by 1 , and compute x k+1 and yk+1 using
equation set (9.4) with the values of xk and yk from the previous step. Continue until
x N and y N are computed.
For our example (omitting many computational details):
With k + 1 = 4 ,
3 1
x4 = x3+1 = x3 + 1x = + = 2 ,
2 2
and
1 2
y3 − x3 2 = · · · ≈ 1.1676

y4 = y3+1 = y2 + .
10

With k + 1 = 5 ,
1 5
x5 = x4+1 = x4 + 1x = 2 + = ,
2 2
and
1 2
y4 − x4 2 = · · · ≈ 0.9039

y5 = y4+1 = y4 + .
10

With k + 1 = 6 ,
5 1
x6 = x5+1 = x5 + 1x = + = 6 ,
2 2
and
1 2
y5 − x5 2 = · · · ≈ 0.3606

y6 = y5+1 = y5 + .
10
Since we had earlier chosen N , the maximum number of steps, to be 6 , we
can stop computing.

Using the Results of the Method


What you do with the results of your computations in depends on why you are doing these
computations. If N is not too large, it is usually a good idea to write the obtained values of

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

in a table for convenient reference (with a note that yk ≈ y(xk ) for each k ) as done in fgure
9.2a for our example. And, whatever the size of N , it is always enlightening to graph —
as done in fgure 9.2b for our example — the corresponding piecewise straight approximation
y = y E,1x (x) to the graph of y = y(x) by drawing straight lines between each (x k , yk ) and
(xk+1 , yk+1 ) .

On Doing the Computations


The frst few times you use Euler’s method, attempt to do all the computations by hand. If the
numbers become too awkward to handle, use a simple calculator and decimal approximations.
This will help you understand and appreciate the method. It will also help you appreciate the
tremendous value of programming a computer to do the calculations in the second part of the
What Can Go Wrong 197

Y
k xk yk
0 0 1 1.0
1 0.5 1.1000
2 1.0 1.1960
3 1.5 1.2390 0.5
4 2.0 1.1676
5 2.5 0.9039
6 3.0 0.3606 0
0 0.5 1.0 1.5 2.0 2.5 3.0 X
(a) (b)

Figure 9.2: Results of Euler’s method to solve 5y ′ − y 2 = −x 2 with y(0) = 1 using


1x = 1/2 and N = 6 : (a) The numerical solution in which yk ≈ y(x k ) (for
k ≥ 3 , the values of yk are to the nearest 0.0001 ). (b) The graph of the
corresponding approximate solution y = y E,1x (x) .

method. That, of course, is how one should really carry out the computations in the second part
of Euler’s method.
In fact, Euler’s method may already be one of the standard procedures in your favorite com-
puter math package. Still, writing your own version is enlightening, and is highly recommended
for the good of your soul.

9.3 What Can Go Wrong


Do not forget that Euler’s method does not yield exact answers. Instead, it yields values

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

with
yk ≈ y(xk ) for k > 0 .
What’s more, each yk+1 is based on the approximation

y(xk + 1x) ≈ y(x k ) + 1x · f (xk , y(xk ))

with y(xk ) being replaced with approximation yk when k > 0 . So we are computing approxi-
mations based on previous approximations.
Because of this, the accuracy of the approximation yk ≈ y(xk ) , especially for larger values
of k , is a serious issue. Consider the work done in the previous section: Just how well can we
trust the approximation
y(3) ≈ 0.3606
obtained for the solution to initial-value problem (9.3)? In fact, it can be shown that

y(3) = −.23699 to the nearest 0.00001 .


198 Euler’s Numerical Method

Y Y
4 4

3 approx. soln. 3

2 2

true soln.
1 1

0 0
0 1 2 3 4X 0 1 /////
//// 3 /////
2 ///// 4 X

−1 −1 IIIIIIIIIIIIIIIIIIII
IIIIIIIIIIIIIIIIIIII
(a) (b)

Figure 9.3: Catastrophic failure of Euler’s method in solving y ′ = (y − 1)2 with


y(0) = −1.3 : (a) Graphs of the true solution and the approximate solution. (b)
Same graphs with a slope feld, the graph of the equilibrium solution, and the
graph of the true solution to y ′ = (y − 1)2 with y(x 1 ) = y1 .

So our approximation is not very good!


To get an idea of how the errors can build up, look back at fgure 9.1a on page 192. You can see
that, if the graphs of the true solutions to the differential equation are generally concave up (as in
the fgure), then the tangent line approximations used in Euler’s method lie below the true graphs,
and yield underestimates for the approximations. Over several steps, these underestimates can
build up so that the yk ’s are signifcantly below the actual values of the y(xk )’s .
Likewise, if the graphs of the true solutions are generally concave down, then the tangent
line approximations used in Euler’s method lie above the true graphs, and yield overestimates
for the approximations.
Also keep in mind that most of the tangent line approximations used in Euler’s method are
not based on lines tangent to the true solution, but on lines tangent to solution curves passing
through the (xk , yk )’s . This can lead to the “catastrophic failure” illustrated in fgure 9.3a. In
this fgure, the true solution to

dy 13
= (y − 1)2 with y(0) = − ,
dx 10

is graphed along with the graph of the approximate solution generated from Euler’s method with
1x = 1/2 . Exactly why the graphs appear so different becomes apparent when we superimpose
the slope feld in fgure 9.3b. The differential equation has an unstable equilibrium solution
y = 1 . If y(0) < 1 , as in the above initial-value problem, then the true solution y(x) should
converge to 1 as x → ∞ . Here, however, one step of Euler’s method overestimated the value
of y1 enough that (x1 , y1 ) ended up above equilibrium and in the region where the solutions
diverge away from the equilibrium. The tangent lines to these solutions led to higher and higher
values for the subsequently computed yk ’s . Thus, instead of correctly telling us that

lim y(x) = 1 ,
x→∞
Reducing the Error 199

Y y = y(x) Y y = y(x)
y(x max ) y(x max )

yN
yN
y0 y = ŷ(x)
X X
x0 x max x0 x max
(a) (b)

Figure 9.4: Two approximations y N of y(x max ) where y is the solution to y ′ = f (x, y)
with y(x 0 ) = y0 : (a) Using Euler’s method with 1x equaling the distance
from x 0 to x max . (b) Using Euler’s method with 1x equaling half the distance
from x 0 to x max (Note: ŷ is the solution to y ′ = f (x, y) with y(x 1 ) = y1 .)

this application of Euler’s method suggests that

lim y(x) = ∞ .
x→∞

A few other situations where blindly applying Euler’s method can lead to misleading results
are illustrated in the exercises (see exercises 9.6, 9.7, and 9.8, 9.9). And these sorts of problems
are not unique to Euler’s method. Similar problems can occur with all numerical methods for
solving differential equations. Because of this, it is highly recommended that Euler’s method
(or any other numerical method) be used only as a last resort. Try the methods developed in the
previous chapters frst. Use a numerical method only if the other methods fail to yield usable
formulas or equations.
Unfortunately, the world is flled with frst-order differential equations for which numerical
methods are the only practical choices. So be sure to skim the next section on improving the
method. Also, if you must use Euler’s method (or any other numerical method), be sure to do a
reality check. Graph the corresponding approximation on top of the slope feld for the differential
equation, and ask yourself if the approximations are reasonable. In particular, watch out that
your numerical solution does not “jump” over an unstable equilibrium solution.

9.4 Reducing the Error


Smaller Step Sizes
Suppose we are applying Euler’s method to a given initial-value problem over some interval
[x0 , xmax ] . The one parameter we can adjust is the step size, 1x (or, equivalently, the number
of steps, N , in going from x0 to xmax ). By shrinking 1x (increasing N ), at least two good
things are typically accomplished:
1. The error in the underlying approximation

y(x k + 1x) ≈ y(x k ) + 1x · f (xk , y(xk ))

is reduced.
200 Euler’s Numerical Method

1x = 1
1.0

1
1x =
0.5 2

1
true solution 1x =
4
1
1x =
0 8
0 0.5 1.0 1.5 2.0 2.5 3.0 X

Figure 9.5: Graphs of the different piecewise straight line approximations of the solution to
5y ′ − y 2 = −x 2 with y(0) = 1 obtained by using Euler’s method with
different values for the step size 1x = 1/2 . Also graphed is the true solution.

2. The slope in the piecewise straight approximation y = y E,1x (x) is recomputed at more
points, which means that this approximation can better match the bends in the slope feld
for the differential equation.

Both of these are illustrated in fgure 9.4.


Accordingly, we should expect that shrinking the step size in Euler’s method will yield
numerical solutions that more accurately approximate the true solution. We can experimentally
test this expectation by going back to our initial-value problem
dy
5 − y 2 = −x 2 with y(0) = 1 ,
dx
computing (as you’ll be doing for exercise 9.5) the numerical solutions arising from Euler’s
method using, say,
1 1 1
1x = 1 , 1x = , 1x = and 1x = ,
2 4 8
and then graphing the corresponding piecewise straight approximations over the interval [0, 3]
along with the graph of the true solution. Do this, and you will get the graphs in fgure 9.5.1 As
expected, the graphs of the approximate solutions steadily approach the graph of the true solution
as 1x gets smaller. It’s even worth observing that the distance between the true value for y(3)
and the approximated value appears to be cut roughly in half each time 1x is cut in half.
In fact, our expectations can be rigorously confrmed. In the next section, we will analyze
the error in using Euler’s method to approximate y(x max ) where y is the solution to a frst-order
initial-value problem
dy
= f (x, y) with y(x0 ) = y0 .
dx

1 The graph of the “true solution” in fgure 9.5 is actually the graph of a very accurate approximation. The difference
between this graph and the graph of the true solution is less than the thickness of the curve used to sketch it.
Reducing the Error 201

Assuming f is a “reasonably smooth” function of x and y , we will discover that there is a


corresponding constant M such that

|y(xmax ) − y N | < M · 1x (9.5)

where y N is the approximation to y(xmax ) generated from Euler’s method with step size 1x .
Inequality (9.5) is an error bound. It describes the worst theoretical error in using y N for
y(xmax ) . In practice, the error may be much less than suggested by this bound, but it cannot
be any worse (unless there are other sources of error). Since this bound shrinks to zero as 1x
shrinks to zero, we are assured that the approximations to y(xmax ) obtained by Euler’s method
will converge to the correct value of y(xmax ) if we repeatedly use the method with step sizes
shrinking to zero. In fact, if we know the value of M and wish to keep the error below some
small positive value, we can use error bound (9.5) to pick a step size, 1x , that will ensure the
error is below that desired value. Unfortunately,

1. M can be fairly large.

2. In practice (as we will see), M can be diffcult to determine.

3. Error bound (9.5) does not take into account the round-off errors that normally arise in
computations.

Let’s briefy consider the problem of round-off errors. Inequality (9.5) is only the error
bound arising from the theoretically best implementation of Euler’s method. In a sense, it is an
“ideal error bound” because it is based on all the computations being done with infnite precision.
This is rarely practical, even when using a computer math package that can do infnite precision
arithmetic — the expressions for the numbers rapidly become too complicated to be usable,
even by the computer math packages, themselves. In practice, the numbers must be converted to
approximations with fnite precision, say, decimal approximations accurate to the nearest 0.0001
as done in the table on page 197.
Don’t forget that the computations in each step involve numbers from previous steps, and
these computations are affected by the round-off errors from those previous steps. So the ultimate
error due to round-off will increase as the number of steps increases. With modern computers,
the round-off error resulting from each computation is usually very small. Consequently, as long
as the number of steps N remains relatively small, the total error due to round-off will usually
be insignifcant compared to the basic error in Euler’s method. But if we attempt to reduce
the error in Euler’s method by taking the step size very, very small, then we must take many,
many more steps to go from x 0 to the desired xmax . It is quite possible to reach a point where
the accumulated round-off error will negate the theoretic improvement in accuracy of the Euler
method described by inequality (9.5).

Better Methods
Be aware that Euler’s method is a relatively primitive method for numerically solving frst-order
initial-value problems. Refnements on the method can yield schemes in which the approxima-
tions to y(xmax ) converge to the true value much faster as the step size decreases. For example,
instead of using the tangent line approximation in each step,

yk+1 = yk + 1x · f (xk , yk ) ,
202 Euler’s Numerical Method

we might employ a “tangent parabola” approximation that better accounts for the bend in the
graphs. (However, writing a program to determine this “tangent parabola”, can be tricky.)
In other approaches, the f (xk , yk ) in the above equation is replaced with a cleverly chosen
weighted average of values of f (x, y) computed at cleverly chosen points near (xk , yk ) . The
idea is that this yields a straight a line approximation with the slope adjusted to reduce the over-
or undershooting noted a page or two ago. At least two of the more commonly used methods,
the “improved Euler method” and the “fourth-order Runge-Kutta method”, take this approach.
Numerous other methods may also worth learning if you are going to make extensive use
of numerical methods. However, an extensive discussion of numerical methods beyond Euler’s
would take us beyond the brief introduction to numerical methods intended by this author for this
chapter. So let us save a more complete discussion of these alternative methods for the future.


9.5 Error Analysis for Euler’s Method
The Problem and Assumptions
Throughout this section we will be concerned with the accuracy of numerical solutions to some
frst-order initial-value problem
dy
= f (x, y) with y(x0 ) = y0 . (9.6)
dx
The precise results will be given in theorem 9.1, somewhere below. For this theorem, L is some
fnite length, and we will assume there is a corresponding rectangle in the XY –plane

R = {(x, y) : x0 ≤ x ≤ x0 + L and ymin < y < ymax }

such that all of the following holds:

1. f and its frst partial derivatives are continuous, bounded functions on R . This “bound-
edness” means there are fnite constants A , B and C such that, at each point in R ,

∂ f ∂ f
|f| ≤ A , ≤ B and ≤ C . (9.7)
∂x ∂y

2. There is a unique solution, y = y(x) , to the given initial-value problem valid over the
interval [x 0 , x0 + L] . (We’ll refer to y = y(x) as the “true solution” in what follows.)

3. The rectangle R contains the graph over the interval [x 0 , x0 + L] of the true solution.

4. If x0 ≤ xk ≤ x0 + L and (xk , yk ) is any point generated by any application of Euler’s


method to solve our problem, then (xk , yk ) is in R .

The rectangle R may be the entire vertical strip

{(x, y) : x 0 ≤ x ≤ x0 + L and − ∞ < y < ∞}

∗ Another one of those optional sections for the “interested reader”.


Error Analysis for Euler’s Method 203

if f and its partial derivatives are bounded on this strip. If f and its partial derivatives are not
bounded on this strip, then fnding the appropriate upper and lower limits for this rectangle is
one of the challenges in using the theorem.

Theorem 9.1 (Error bound for Euler’s method)


Let f , x0 , y0 , L and R be as above, and let y = y(x) be the true solution to initial-value
problem (9.6). Then there is a fnite constant M such that

|y(x N ) − y N | < M · 1x (9.8)

whenever

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

is a numerical solution to initial-value problem (9.6) obtained from Euler’s method with step
spacing 1x and total number of steps N satisfying

0 < 1x · N ≤ L . (9.9)

This theorem is only concerned with the error inherent in Euler’s method. Inequality (9.8)
does not take into account errors arising from rounding off numbers during computation. For a
good discussion of round-off errors in computations, the interested reader should consult a good
text on numerical analysis
To prove this theorem, we will derive a constant M that makes inequality (9.8) true. (The
impatient can look ahead to equation (9.16) on page 207.) Accordingly, for the rest of this
section, y = y(x) will denote the true solution to our initial-value problem, and

{ x0 , x1 , x2 , x3 , . . . , x N } and { y0 , y1 , y2 , y3 , . . . , y N }

will be an arbitrary numerical solution to initial-value problem (9.6) obtained from Euler’s method
with step spacing 1x and total number of steps N satisfying inequality (9.9).
Also, to simplify discussion, let us agree that, in all the following, k always denotes an
arbitrary nonnegative integer less than than N .

Preliminary Bounds
Our derivation of a value for M will be based on several basic inequalities and facts from
calculus. These include the inequalities
Z b Z b

|A + B| ≤ |A| + |B| and
ψ(s) ds ≤
|ψ(s)| ds
a a

when a < b . Of course, if |ψ(s)| ≤ K for some constant K , then, whether or not a < b ,
Z b
|ψ(s)| ds ≤ K |b − a|
a

Also remember that, if φ = φ(x) is continuous and differentiable, then


Z b

φ(a) − φ(b) = -- ds .
a ds
204 Euler’s Numerical Method

Combining the above, we get

Corollary 9.2
Assume φ is a continuous differentiable function on some interval. Assume further that φ ′ ≤ K
on this interval for some constant K . Then, for any two points a and b in this interval,

|φ(a) − φ(b)| ≤ K |b − a| .

We will use this corollary twice.


First, we apply it with φ(x) = f (x, y(x)) . Recall that, by the chain rule in chapter 7,
d ∂f ∂ f dy
f (x, y(x)) = + ,
dx ∂x ∂ y dx

which we can rewrite as


d ∂f ∂f
f (x, y(x)) = + f (x, y)
dx ∂x ∂y
whenever y = y(x) is a solution to y ′ = f (x, y) . Applying bounds (9.7), this then yields

d f
≤ ∂ f + ∂ f | f (x, y)| ≤ B + C A

dx ∂x ∂y at every point in R .

The above corollary (with φ(x) = f (x, y(x)) and K = B + C A ) then tells us that

| f (a, y(a)) − f (b, y(b))| ≤ (B + C A)(b − a) (9.10)

whenever x 0 ≤ a ≤ b ≤ x0 + L .
The second application of the above corollary is with φ(y) = f (xk , y) . Here, y is the
′ ∂ f/ ∂ f/
variable, x remains constant, and φ = ∂ y . Along with the fact that ∂ y < C on rectangle
R , this corollary immediately gives us

| f (xk , b) − f (xk , a)| ≤ C |b − a| (9.11)

whenever a and b are any two points in the interval [x0 , x0 + L] .

Maximum Error in the Underlying Approximation


Now consider the error in the underlying approximation

y(xk + 1x) ≈ y(x k ) + 1x · f (xk , y(xk )) .

Let ǫk+1 be the difference between y(xk + 1x) and the above approximation,

ǫk+1 = y(xk + 1x) − [y(xk ) − 1x · f (xk , y(xk ))] .

Note that this can be rewritten both as

y(xk+1 ) = y(xk ) + 1x · f (xk , y(xk )) + ǫk+1 (9.12)

and as
ǫk+1 = [y(xk + 1x) − y(xk )] − f (xk , y(xk )) · 1x .
Error Analysis for Euler’s Method 205

From basic calculus, we know that


Z x k +1x Z x k +1x
f (xk , y(xk )) · 1x = f (xk , y(xk )) dx = f (xk , y(xk )) d x .
xk xk

We also know y = y(x) satisfes y ′ = f (x, y) . Hence,


Z xk +1x Z x k +1x
dy
y(xk + 1x) − y(xk ) = dx = f (x, y(x)) d x .
xk dx xk

Taking the absolute value of ǫk+1 and applying the last three observations yields

|ǫk+1 | = |[y(xk + 1x) − y(xk )] − f (xk , y(xk )) · 1x|


Z xk +1x Z xk +1x

=
f (x, y(x)) d x − f (xk , y(xk )) d x
xk xk
Z xk +1x

= f (x, y(x)) − f (xk , y(xk )) d x
xk
Z xk +1x
≤ | f (x, y(x)) − f (xk , y(xk ))| d x .
xk

Remarkably, we’ve already found an upper bound for the integrand in the last line (inequality
(9.10), with a = x and b = xk ). Replacing this integrand with this upper bound, and then
doing a little elementary integration yields
Z xk +1x
1
|ǫk+1 | ≤ (B + C A)(x − x k ) d x = (B + C A)(1x)2 .
xk 2

This last inequality combined with equation (9.12) means that we can rewrite the underlying
approximation more precisely as

y(xk+1 ) = y(xk ) + 1x · f (xk , y(xk )) + ǫk+1 (9.13a)


where
1
|ǫk+1 | ≤ (B + C A)(1x)2 . (9.13b)
2

Ideal Maximum Error in Euler’s Method


Now let E k be the difference between y(xk ) and yk ,

E k = y(xk ) − yk .

Because y0 = y(x0 ) :
E 0 = y(x0 ) − y0 = 0 .
More generally, using formula (9.13a) for y(xk +1x) and the formula for yk+1 from Euler’s
method, we have

E k+1 = y(xk+1 ) − yk+1


= y(xk + 1x) − yk+1
 
= y(xk ) + 1x · f (xk , y(xk )) + ǫk+1 − [yk + 1x · f (xk , yk )] .
206 Euler’s Numerical Method

Cleverly rearranging the last line and taking the absolute value leads to

|E k+1 | = |ǫk+1 + [y(xk ) − yk ] + 1x · [ f (xk , y(xk )) − f (xk , yk )]|


= |ǫk+1 + E k + 1x · [ f (xk , y(xk )) − f (xk , yk )]|
≤ |ǫk+1 | + |E k | + |1x · [ f (xk , y(xk )) − f (xk , yk )]| .

Fortunately, from inequality (9.13b), we know

1
|ǫk+1 | ≤ (B + C A)(1x)2 ,
2

and from inequality (9.11) and the defnition of E k , we know

| f (xk , y(xk )) − f (xk , yk )| ≤ C |y(xk ) − yk | = C |E k | .

Combining the last three inequalities, we get

|E k+1 | ≤ |ǫk+1 | + |E k | + |1x · [ f (x k , y(xk )) − f (xk , yk )]|


1
≤ (B + C A)(1x)2 + |E k | + 1x · C |E k |
2
1
≤ (B + C A)(1x)2 + (1 + 1x · C) |E k | .
2

This is starting to look ugly. So let

1
α = (B + C A) and β = 1 + 1x · C ,
2

just so that the above inequality can be written more simply as

|E k+1 | ≤ α(1x)2 + β |E k | .

Remember, E 0 = 0 . Repeatedly applying the last inequality, we then obtain the following:

|E 1 | = |E 0+1 | = α(1x)2 + β |E 0 | = α(1x)2 .

|E 2 | = |E 1+1 | ≤ α(1x)2 + β |E 1 |
≤ α(1x)2 + βα(1x)2 ≤ (1 + β) α(1x)2 .

|E 3 | = |E 2+1 | ≤ α(1x)2 + β |E 2 |
≤ α(1x)2 + β (1 + β) α(1x)2
≤ α(1x)2 + β + β 2 α(1x)2 ≤ 1 + β + β 2 α(1x)2
�  � 
.

..
.

Continuing, we eventually get

|E N | ≤ S N α(1x)2 where S N = 1 + β + β 2 + · · · + β N −1 . (9.14)


Additional Exercises 207

You may recognize S N as a partial sum for a geometric series. Whether you do or not, we have

(β − 1)S N = β S N − S N
= β 1 + β + β 2 + · · · + β N −1 − 1 + β + β 2 + · · · + β N −1
   

= β + β 2 + · · · + β k − 1 + β + β 2 + · · · + β N −1
   

= βN − 1 .

Dividing through by β and recalling what α and β represent then gives us

βN − 1
SN α = α
β −1
(1 + 1x · C) N − 1 (B + C A)
 
(1 + 1x · C) N − 1 B + C A
= · = .
1 + 1x · C − 1 2 1x · 2C

So inequality (9.14) can be rewritten as

(1 + 1x · C) N − 1
|E N | ≤ α(1x)2
1x · C
Dividing out one 1x leaves us with

(1 + 1x · C) N − 1 (B + C A)
 
|E N | ≤ M N ,1x · 1x where M N ,1x = . (9.15)
2C
The claim of theorem 9.1 is almost proven with inequality (9.15). All we need to do now is
to fnd a single constant M such that M N ,1x ≤ M for all possible choices of M and 1x . To
this end, recall the Taylor series for the exponential,

X 1 1 2 1
eX = Xn = 1 + X + X + X3 + · · · .
n! 2 6
n=0

If X > 0 then
1 2 1
1 + X < 1 + X + X + X3 + · · · = eX .
2 6
Cutting out the middle and letting X = 1x · C , this becomes

1 + 1x · C < e1x·C .

Thus, N
(1 + 1x · C) N < e1x·C = e N 1x·C ≤ e LC


where L is that constant with N 1x ≤ L . So

(1 + 1x · C) N − 1 (B + C A)
 
M N ,1x = < M
2C
where
(e LC − 1)(B + C A)
M = . (9.16)
2C
And this (fnally) completes our proof of theorem 9.1 on page 203.
208 Euler’s Numerical Method

Additional Exercises

9.1. Several initial-value problems are given below, along with values for two of the three
parameters in Euler’s method: step size 1x , number of steps N , and maximum variable
of interest xmax . For each, fnd the corresponding numerical solution using Euler’s
method with the indicated parameter values. Do these problems without a calculator or
computer.
dy y 1
a. = with y(1) = −1 ; 1x = and N = 3
dx x 3
dy
b. = −8x y with y(0) = 10 ; xmax = 1 and N = 4
dx
dy 1
c. 4x + = y 2 with y(0) = 2 ; xmax = 2 and 1x =
dx 2
dy y 1
d. + = 4 with y(1) = 8 ; 1x = and N = 6
dx x 2
9.2. Again, several initial-value problems are given below, along with values for two of the
three parameters in Euler’s method: step size 1x , number of steps N , and maxi-
mum variable of interest xmax . For each, fnd the corresponding numerical solution
using Euler’s method with the indicated parameter values. Do these problems with a
(nonprogramable) calculator.
dy p 1
a. = 2x + y with y(0) = 0 ; 1x = and N = 6
dx 2
dy
b. (1 + y) = x with y(0) = 1 ; N =6 and xmax = 2
dx
dy
c. = y x with y(1) = 2 ; 1x = 0.1 and xmax = 1.5
dx
dy 1
d. = cos(y) with y(0) = 0 ; 1x = and N = 5
dx 5
9.3 a. Using your favorite computer language or computer math package, write a program
or worksheet for fnding the numerical solution to an arbitrary frst-order initial-value
problem using Euler’s method. Make it easy to change the differential equation and
the computational parameters (step size, number of steps, etc.).2, 3
b. Test your program/worksheet by using it to re-compute the numerical solutions for
the problems in exercise 9.2, above.

9.4. Using your program/worksheet from exercise 9.3 a with each of the following step sizes,
fnd an approximation for y(5) where y = y(x) is the solution to
dy p
= 3 x 2 + y2 + 1 with y(0) = 0 .
dx
2 If your computer math package uses infnite precision or symbolic arithmetic, you may have to include commands
to ensure your results are given as decimal approximations.
3 It may be easier to compute all the x ’s frst, and then compute the y ’s .
k k
Additional Exercises 209

a. 1x = 1 b. 1x = 0.1 c. 1x = 0.01 d. 1x = 0.001

9.5. Let y be the (true) solution to the initial-value problem considered in section 9.2,
dy
5 − y 2 = −x 2 with y(0) = 1 .
dx
For each step size 1x given below, use your program/worksheet from exercise 9.3 a
to fnd an approximation to y(3) . Also, for each, fnd the magnitude of the error (to
the nearest 0.0001 ) in using the approximation for y(3) , assuming the correct value
of y(3) is −0.23699 .
1 1 1
a. 1x = 1 b. 1x = c. 1x = d. 1x =
2 4 8
e. 1x = 0.01 f. 1x = 0.001 g. 1x = 0.0001

9.6. Consider the initial-value problem


dy 13
= (y − 1)2 with y(0) = − .
dx 10
This is the problem discussed in section 9.3 in the illustration of a “catastrophic failure”
of Euler’s method.
a. Find the exact solution to this initial-value problem using methods developed in earlier
chapters. What, in particular, is the exact value of y(4) ?
b. Using your program/worksheet from exercise 9.3 a, fnd the numerical solution to the
above initial-value problem with xmax = 4 and step size 1x = 1/2 . (Also, confrm
that this numerical solution has been properly plotted in fgure 9.3 on page 198.)
c. Find the approximation to y(4) generated by Euler’s method with each of the follow-
ing step sizes (use your answer to the previous part or your program/worksheet from
exercise 9.3 a). Also, compute the magnitude of the error in using this approximation
for the exact value found in the frst part of this exercise.
1 1 1
i. 1x = 1 ii. 1x = iii. 1x = iv. 1x =
2 4 10

9.7. Consider the following initial-value problem


dy
= −4y with y(0) = 3 .
dx
The following will illustrate the importance of choosing appropriate step sizes.
a. Find the numerical solution using Euler’s method with 1x = 1/2 and N being any
large integer (this will be more easily done by hand than using calculator!). Then do
the following:
i. There will be a pattern to the yk ’s . What is that pattern? What happens as k → ∞ ?
ii. Plot the piecewise straight approximation corresponding to your numerical solution
along with a slope feld for the above differential equation. Using these plots, decide
whether your numerical solution accurately describes the true solution, especially
as x gets large.
210 Euler’s Numerical Method

iii. Solve the above initial-value problem exactly using methods developed in earlier
chapters. What happens to y(x) as x → ∞ ? Compare this behavior to that of
your numerical solution. In particular, what is the approximate error in using yk
for y(xk ) when xk is large?
b. Now fnd the numerical solution to the above initial-value problem using Euler’s
method with 1x = 1/10 and N being any large integer (do this by hand, looking for
patterns in the yk ’s )). Then do the following:
i. Find a relatively simple formula describing the pattern in the yk ’s .
ii. Plot the piecewise straight approximation corresponding to this numerical solution
along with a slope feld for the above differential equation. Does this numerical
solution appear to be signifcantly better (more accurate) than the one found in part
9.7 a?

9.8. In this problem we’ll see one danger of blindly applying a numerical method to solve
an initial-value problem. The initial-value problem is
dy 3
= with y(0) = 0 .
dx 7 − 3x

a. Find the numerical solution to this using Euler’s method with step size 1x = 1/2 and
xmax = 5 . (Use your program/worksheet from exercise 9.3 a).
b. Sketch the piecewise straight approximation corresponding to the numerical solution
just found.
c. Sketch the slope feld for this differential equation, and fnd the exact solution the
above initial-value problem by simple integration.
d. What happens in the true solution as x → 7/3 ?
e. What can be said about the approximations to y(xk ) obtained in the frst part when
xk > 7/3 ?

9.9. What goes wrong with attempting to fnd a numerical solution to


2 dy
(y − 1) /3 = 1 with y(0) = 0
dx

using Euler’s method with, say, step size 1x = 1/2 ?

You might also like