# Elementary differential equations 7th edition - Boyce W.E

ISBN 0-471-31999-6

**Download**(direct link)

**:**

**50**> 51 52 53 54 55 56 .. 486 >> Next

FIGURE 2.7.1 A tangent line approximation.

98

Chapter 2. First Order Differential Equations

Continuing in this manner, we use the value of y calculated at each step to determine the slope of the approximation for the next step. The general expression for yn+1 in terms of tn, Wp and yn is

yn+1 = yn + f (tn, yn )(tn+1 — tn ^, n = 0, 1, 2^... (6)

If we introduce the notation fn = f (tn, yn), then we can rewrite Eq. (6) as

yn+1 = yn + n • (tn+r — tn), n = 0 12_.. (7)

Finally, if we assume that there is a uniform step size h between the points t0, tv t2,...,

then t x = tn + h for each n and we obtain Euler’s formula in the form

yn+1 = yn + fn^ n = 0 1 2_.. (8)

To use Euler’s method you simply evaluate Eq. (7) or Eq. (8) repeatedly, depending

on whether or not the step size is constant, using the result of each step to execute the next step. In this way you generate a sequence of values y1, y2, y3,... that approximate the values of the solution $(t) at the points tv t2, t3,.... If, instead of a sequence of points, you need an actual function to approximate the solution $( t), then you can use the piecewise linear function constructed from the collection of tangent line segments. That is, let y be given by Eq. (2) in [t0, tj, by Eq. (4) in [tp t2], and, in general, by

y = yn + f(tn, yn)(t — tn) (9)

in [tn, tn+1].

Consider the initial value problem

dy = 3 + e-‘ - 1 y, y(0) = 1. (10)

Use Euler’s method with step size h = 0.1 to find approximate values of the solution of Eqs. (10) at t = 0.1, 0.2, 0.3, and 0.4. Compare them with the corresponding values of the actual solution of the initial value problem.

Proceeding as in Section 2.1, we find the solution of Eqs. (10) to be

y = $(t) = 6 - 2e-t - 3e-t/2. (11)

To use Euler’s method we note that in this case f (t, y) = 3 + e-t - y/2. Using the initial values t0 = 0 and y0 = 1, we find that

f0 = f(t0, y0) = f(0, 1) = 3 + e0 - 0.5 = 3 + 1 - 0.5 = 3.5

and then, from Eq. (8) with n = 0,

yx = y0 + f^h = 1 + (3.5)(0.1) = 1.35.

At the next step we have

f1 = f(0.1, 1.35) = 3 + e-01 - (0.5)(1.35) = 3 + 0.904837 - 0.675 = 3.229837

and then

y2 = y1 + flh = 1.35 + (3.229837)(0.1) = 1.672984.

2.7 Numerical Approximations: Euler’s Method

99

Repeating the computation two more times, we obtain

f2 = 2.982239, y3 = 1.971208

and

f3 = 2.755214, y4 = 2.246729.

Table 2.7.1 shows these computed values, the corresponding values of the solution (11), and the differences between the two, which is the error in the numerical approximation.

TABLE 2.7.1 A Comparison of Exact Solution with Euler Method for h = 0.1 for

/ = 3 + e-t - Iy, y(0) = 1

t Exact Euler with h = 0.1 Error

0.0 1.0000 1.0000 0.0000

0.1 1.3366 1 . 3500 0.0134

0.2 1.6480 1.6730 0.0250

0.3 1.9362 1 . 9712 0.0350

0.4 2.2032 2.2467 0.0435

The purpose of Example 1 is to show you the details of implementing a few steps of Euler’s method so that it will be clear exactly what computations are being executed. Of course, computations such as those in Example 1 are usually done on a computer. Some software packages include code for the Euler method, while others do not. In any case, it is easy to write a computer program to carry out the calculations required to produce results such as those in Table 2.7.1. The outline of such a program is given below; the specific instructions can be written in any high-level programming language.

The Euler Method

Step 1. define f (t, y)

Step 2. input initial values t0 and y0

Step 3. input step size h and number of steps n

Step 4. output 10 and y0

Step 5. for j from 1 to n do

Step 6. k 1 = f (t, y)

y = y + h * k1 t = t + h Step 7. output t and y

Step 8. end

The output of this algorithm can be numbers listed on the screen or printed on a printer, as in the third column of Table 2.7.1. Alternatively, the calculated results can be displayed in graphical form.

100

Chapter 2. First Order Differential Equations

EXAMPLE

2

Consider again the initial value problem (10),

dt = 3 + e~‘ - 1 y, y(0) = 1.

Use Euler’s method with various step sizes to calculate approximate values of the solution for 0 < t < 5. Compare the calculated results with the corresponding values of the exact solution (11),

y = 0(t) = 6 - 2e-t - 3e-t/2.

We used step sizes h = 0.1, 0.05, 0.025, and 0.01, corresponding respectively to 50, 100, 200, and 500 steps to go from t = 0 to t = 5. The results of these calculations, along with the values of the exact solution, are presented in Table 2.7.2. All computed entries are rounded to four decimal places, although more digits were retained in the intermediate calculations.

TABLE 2.7.2 A Comparison of Exact Solution with Euler Method for Several Step Sizes h for y1 = 3 + — 2y, y(0) = 1

t Exact h = 0.1 h = 0.05 h = 0.025 h = 0.01

0.0 1.0000 1 . 0000 1.0000 1 .0000 1 . 0000

1.0 3.4446 3.5175 3.4805 3.4624 3.4517

2.0 4.6257 4.7017 4.6632 4.6443 4.6331

3.0 5.2310 5.2918 5.2612 5.2460 5.2370

4.0 5.5574 5.6014 5.5793 5.5683 5.5617

5.0 5.7403 5.7707 5.7555 5.7479 5.7433

**50**> 51 52 53 54 55 56 .. 486 >> Next