SDSU

 

Math 122 - Calculus for Biology II
Fall Semester, 2004
Numerical Methods of Differential Equations -Examples

 © 2000, All Rights Reserved, SDSU & Joseph M. Mahaffy
San Diego State University -- This page last updated 01-Mar-04


Numerical Methods for Differential Equations - Examples

 

  1. Example of Euler's Method
  2. Example 2 of Euler's Method
  3. Variable Growth Population Model

This section examines several examples of differential equations that are solved numerically using Euler's method. It cannot be emphasized enough that these numerical methods are best studied in a computer laboratory. (See the Excel worksheet that has been provided for working Euler's method and Improved Euler's method problems by computer.) For practical examples, numerical techniques are often the best method for studying a differential equation. This is why many software programs, including Maple and MatLab, contain special programs for numerically solving a differential equation. It is also very important to remember that Euler's method is great for both a beginning point in studying numerical differential equations and helping to understand the theory behind these methods, but is rarely of any practical value in real applications. If you really need to numerically solve a differential equation, then some other method, such as the Runge-Kutta-Fehlberg method (used by Maple and MatLab and discussed in almost any modern numerical analysis text), should be used. Still for pedagogical purposes, it is valuable to go through a couple of examples by hand, which is what we do below, and you should do with the homework assignment.

Example 1: Consider the initial value problem given by

y ' = -2y 2, y(0) = 2.

With a stepsize of h = 0.2, use Euler's method to approximate y(t) at t = 1, i.e., take five Euler steps. Show that the actual solution of this problem is

Determine the percent error between the approximate solution and the actual solution at t = 1.

Solution: The Euler's formula for this initial value problem is given by

yn +1 = yn - h (2yn2) = yn - 0.4yn2.

The initial condition y(0) = 2 implies that t0 = 0 and y0 = 2. Below we simulate the differential equations with Euler's method by setting up a table. Here are the first five iterates to reach t = 1.

tn

yn
t0 = 0
y0 = 2
t1 = t0 + h = 0.2
y1 = y0 - 0.4y02 = 2 - 0.4(4) = 0.4
t2 = t1 + h = 0.4
y2 = y1 - 0.4y12 = 0.4 - 0.4(0.16) = 0.336
t3 = t2 + h = 0.6
y3 = y2 - 0.4y22 = 0.336 - 0.4(.1129) = 0.2908
t4 = t3 + h = 0.8
y4 = y3 - 0.4y32 = 0.2908 - 0.4(.08459) = 0.2570
t5 = t4 + h = 1.0
y5 = y4 - 0.4y42 = 0.2570 - 0.4(.06605) = 0.2306

 

If the solution is given by y(t) = 2(4t + 1)-1, so y '(t) = -2(4t + 1)-2(4) = -8(4t + 1)-2. By computing -2y(t)2, we see that -2y(t)2 = -2(2(4t + 1)-1)2 = -8(4t + 1)-2. Thus, the differential equation is satisfied by the solution that is given. By substituting t = 1 into the solution, we have y(1) = 0.4. The percent error is found by the formula below

Example 2: Consider the initial value problem given by

With a stepsize of h = 0.25, use Euler's method to approximate y(t) at t = 1, i.e., take four Euler steps. Show that the actual solution of this problem is

Determine the percent error between the approximate solution and the actual solution.

Solution: This problem is similar to the last example. The Euler's formula for this initial value problem is given by

yn +1 = yn + h (2tn/yn) = yn + 0.5tn/yn.

The initial condition y(0) = 2 implies that t0 = 0 and y0 = 2. Below we simulate the differential equations with Euler's method by setting up a table. Here are the first five iterates to reach t = 1.

tn

yn
t0 = 0
y0 = 2
t1 = t0 + h = 0.25
y1 = y0 + 0.5t0/y0 = 2 + 0.5(0/2) = 2
t2 = t1 + h = 0.5
y2 = y1 + 0.5t1/y1 = 2 + 0.5(0.25/2) = 2.0625
t3 = t2 + h = 0.75
y3 = y2 + 0.5t2/y2 = 2.0625 + 0.5(0.5/2) = 2.1875
t4 = t3 + h = 1.0
y4 =y3 + 0.5t3/y3 = 2.1875 + 0.5(0.75/2) = 2.375

 

If the solution is given by y(t) = (2t2 + 4)0.5, so y '(t) = 0.5(2t2 + 4)-0.5(4t) = 2t(2t2 + 4)-0.5. By computing 2t/y(t), we see that 2t/y(t) = 2t/(2t2 + 4)0.5= 2t(2t2 + 4)-0.5. Thus, the differential equation is satisfied by the solution that is given. By substituting t = 1 into the solution, we have y(1) = 61/2 = 2.4495. The percent error is found by the formula below

Example 3: Our discrete model for the population growth of the U. S. showed that the rate of growth has been declining for most of the census counts. Below is a Malthusian growth model with a time varying growth rate.

P' = (0.2 - 0.02t)P, P(0) = 5000,

where t is in years. Use Euler's method with a stepsize of h = 0.2 to approximate P(t) at t = 1, i.e., take five Euler steps. Show that the actual solution of this problem is

P(t) = 5000 exp(0.2t - 0.01t2).

Determine the percent error between the approximate solution and the actual solution. Use the actual solution to find the maximum population of this growth model and when this occurs.

Solution: We begin by showing that the solution above satisfies the differential equation. Clearly, it satisfies the initial condition (substituting t = 0). Upon differentiation, the chain rule gives

P'(t) = 5000 exp(0.2t - 0.01t2)(0.2 - 0.02t).

Thus,

P'(t) = (0.2 - 0.02t)P(t).

The Euler's formula for this problem becomes

Pn+1 = Pn + h(0.2 – 0.02tn)Pn.

As we have done in previous problems, we create a table beginning with the initial conditions t0 = 0 and P0 = 5000.

tn

Pn
t0 = 0
P0 = 5000
t1 = t0 + h = 0.2
P1 = P0 + 0.2(0.2-0.02t0)P0 = 5000 + 0.04(5000) = 5200
t2 = t1 + h = 0.4
P2 = P1 + 0.2(0.2-0.02t1)P1
= 5200 + 0.2(0.2 - 0.02(0.2))5200 = 5403.84
t3 = t2 + h = 0.6
P3 = P2 + 0.2(0.2-0.02t2)P2
= 5403.84 + 0.2(0.2 - 0.02(0.4))5403.84 = 5611.35
t4 = t3 + h = 0.8
P4 = P3 + 0.2(0.2-0.02t3)P3
= 5611.35 + 0.2(0.2 - 0.02(0.6))5611.35 = 5822.33
t5 = t4 + h = 1.0
P5 = P4 + 0.2(0.2-0.02t4)P4
= 5822.33 + 0.2(0.2 - 0.02(0.8))5822.33 = 6036.60

Combining the results in the table above with the actual solution given above, we can create a table that shows the percent error.

tn

Euler's Pn

Actual P(t)

% Error

0

5000

5000

0

0.2

5200

5202.0

0.04

0.4

5403.8

5407.8

0.07

0.6

5611.35

5617.2

0.10

0.8

5822.3

5830.1

0.13

1

6036.6

6046.2

0.16

Since this population begins by growing, its maximum can be found by determining when the derivative is equal to zero. Since

P'(t) = (0.2 - 0.02t)P(t)

and because P(t) is positive, the derivative is zero (growth rate falls to zero) when 0.2 - 0.02t = 0 or t = 10 years. This is substituted into the actual solution for the differential equation giving

P(10) = 5000 e1 = 13,591.4.