Differential Equations 7.1: The Error of the Method of Euler

Differential Equations

Units and Topics

Unit 7. Numerical Methods

7.1 The Error of the Method of Euler

The method of Euler gives approximate values, and each value has an error. This topic measures that error. It covers the error of one step, the error at a fixed time, a way to estimate the error without the exact solution, and the step sizes for which the method fails.

You need Topic 1.3 for this topic. Part 1 uses the second derivative and the tangent line of calculus.

1. The Error of One Step

The example of this topic is the initial value problem of Topic 1.3.

y′ = t − y with y(0) = 1

Its exact solution is y = t − 1 + 2e−t. One step of the method of Euler follows the tangent line for the time h. The solution curve bends away from its tangent line, and the second derivative measures the bending. For a short time h, calculus gives the approximation below.

y(t + h) ≈ y(t) + h y′(t) + 1/2h² y″(t)

The first two terms on the right are the value of the method of Euler. The third term is what the method leaves out.

The local error. The error of one step that starts on the exact solution is called the local error. It is approximately (1/2)h² y″(t), so it is proportional to h².

For the example, the second derivative follows from the equation.

y″ = 1 − y′differentiate both sides of y′ = t − yy″ = 1 − t + ysubstitute y′ = t − yy″(0) = 1 − 0 + 1at the starting point (0, 1)y″(0) = 2the second derivative at the start1/2h² y″(0) = h²the approximate local error of the first step

The table compares this estimate with the true error of the first step.

Step size hValue of the methodExact value y(h)Local errorh²
0.20.80.837460.037460.04
0.10.90.909670.009670.01
0.050.950.952460.002460.0025

When h is divided by 2, the local error is divided by about 4.

2. The Error at a Fixed Time

The error of the method at a fixed time, after many steps, is called the global error. To reach the time T, the method takes T/h steps. Each step adds a local error that is proportional to h².

number of steps = T/hthe time T divided by the step sizeerror of each step ≈ Ch²the local error, with a constant Cglobal error ≈ T/h(Ch²)the errors of the steps add upglobal error ≈ CThone factor h cancels

This count is rough, because an error that was made early also grows or shrinks during the later steps. The conclusion is still correct: the global error is proportional to h. The table shows the values at t = 1 for the example. The exact value is 0.735759.

Step size hNumber of stepsValue at t = 1Global errorError divided by h
0.1100.6973570.0384020.384
0.05200.7169720.0187870.376
0.025400.7264650.0092940.372
0.0125800.7311360.0046230.370

The last column is nearly constant. For this problem, the global error at t = 1 is about 0.37h.

The order of a method. A method has the order p when its global error is proportional to hp. The method of Euler has the order 1. Its local error is proportional to h², and its global error is proportional to h.

Try it: local errors and the global error

The purple curve is the exact solution with y(0) = 1. The green points are the values of the method of Euler. Each gray curve is the exact solution that passes through one green point. In each step, the method moves from one gray curve to the next one. The slider sets the number of steps from t = 0 to t = 2.

3. An Estimate of the Error Without the Exact Solution

In practice, the exact solution is not known, so the error cannot be calculated by a subtraction. The order of the method gives an estimate. Run the method twice, with the step sizes h and h/2. Let E be the error of the second run. The error of the first run is then about 2E.

y(T) ≈ Y₁ + 2Ethe first run, with the step size h and the value Y₁y(T) ≈ Y₂ + Ethe second run, with the step size h/2 and the value Y₂Y₁ + 2E ≈ Y₂ + Eboth right sides approximate the same numberE ≈ Y₂ − Y₁subtract Y₁ and E from both sides

The difference of the two runs estimates the error of the run with the smaller step size. For the example at t = 1, with h = 0.1 and 0.05:

Y₂ − Y₁ = 0.716972 − 0.697357the two values of the table of Part 2Y₂ − Y₁ = 0.019615the estimate of the error of the second run

The true error of the second run is 0.018787. The estimate is close to it, and it did not use the exact solution.

The estimate can also correct the value. Adding E to Y₂ gives a better approximation.

Y₂ + E ≈ Y₂ + (Y₂ − Y₁)add the estimate of the errorY₂ + E ≈ 2Y₂ − Y₁collect the terms2(0.716972) − 0.697357 = 0.736587the corrected value

The exact value is 0.735759. The error of the corrected value is 0.000828, which is about 23 times smaller than the error of Y₂. This correction is called Richardson extrapolation.

4. Step Sizes for Which the Method Fails

The equation y′ = −20y with y(0) = 1 has the solution y = e−20t, which decreases quickly toward 0. For this equation, each step of the method multiplies the value by the same factor.

yn+1 = yₙ + h(−20yₙ)one step of the methodyn+1 = (1 − 20h)yₙfactor out yₙyₙ = (1 − 20h)ⁿafter n steps, with y₀ = 1

The values of the method decrease toward 0 only when the factor 1 − 20h is between −1 and 1.

1 − 20h is greater than −1the condition on the factor20h is less than 2add 20h and 1 to both sidesh is less than 0.1divide by 20
Step size hFactor 1 − 20hValue after 50 stepsBehavior
0.040.2about 10⁻³⁵decreases, like the solution
0.09−0.80.000014changes its sign in each step and decreases
0.11−1.29100changes its sign in each step and grows

With h = 0.11, the values grow without limit, and the exact solution is nearly 0. The method is called unstable for this step size.

The condition for stability. For the equation y′ = −ky with a positive constant k, the method of Euler is stable only when h is less than 2/k.

An equation with a large k forces a small step size, even at times when the solution is nearly constant. Equations of this kind are called stiff.

5. The Smallest Useful Step Size

A computer stores a number with about 16 digits, so each arithmetic operation has a small rounding error, about 10⁻¹⁶ times the size of the number. A run with the step size h has T/h steps, and the rounding errors add up. The total error has two parts.

  • The error of the method is proportional to h. It decreases when h decreases.
  • The rounding error is proportional to 1/h. It increases when h decreases.

For the method of Euler, the two parts are equal near h = 10⁻⁸. A smaller step size does not improve the result. A run with this step size needs 100 million steps for each unit of time, so a method of a higher order is the better way to an accurate result. Topic 7.2 covers such methods.

Common Mistakes

  • Confusing the local error with the global error. The local error of the method of Euler is proportional to h², and the global error is proportional to h.
  • Expecting the error to be divided by 4 when h is divided by 2. For the method of Euler, the global error is divided by about 2.
  • Using Y₂ − Y₁ as the error of the run with the larger step size. It estimates the error of the run with the smaller step size.
  • Trusting a result because the step size is small. The step size must also satisfy the condition for stability.
  • Writing the corrected value as 2Y₁ − Y₂. The run with the smaller step size has the factor 2.

Summary

ItemResult
Local errorAbout (1/2)h² y″(t), proportional to h²
Global errorProportional to h
Order of the method of Euler1
Estimate of the error of the run with h/2Y₂ − Y₁
Corrected value2Y₂ − Y₁
Stability for y′ = −kyh less than 2/k

Practice

Work each problem on paper first. Then open the answer to check your work.

1. For y′ = t − y with y(0) = 1, the local error of the first step is about h². Estimate the local error of a first step with h = 0.02.

h² = (0.02)²the estimate of Part 1h² = 0.0004the approximate local error

The true local error is 0.000397.

2. A run of the method of Euler with h = 0.1 has the global error 0.012 at t = 3. Estimate the global error at t = 3 for h = 0.02.

0.1/0.02 = 5the step size is divided by 50.012/5 = 0.0024the global error is proportional to h

3. The method of Euler for y′ = y with y(0) = 1 gives the value 2.25 at t = 1 with h = 0.5, and the value 2.4414 with h = 0.25. Estimate the error of the second value, and find the corrected value.

E ≈ 2.4414 − 2.25the difference of the two runsE ≈ 0.1914the estimate of the error of the second run2(2.4414) − 2.25 = 2.6328the corrected value

The exact value is e, which is 2.7183. The true error of the second run is 0.2769. The estimate is rough, because both step sizes are large.

4. Find the step sizes for which the method of Euler is stable for y′ = −8y.

yn+1 = (1 − 8h)yₙone step of the method1 − 8h is greater than −1the condition on the factor8h is less than 2add 8h and 1 to both sidesh is less than 0.25divide by 8

5. For y′ = −8y with y(0) = 1 and h = 0.2, find y₁, y₂, and y₃. Describe the behavior.

1 − 8(0.2) = −0.6the factor of one stepy₁ = −0.6the first stepy₂ = 0.36multiply by −0.6y₃ = −0.216multiply by −0.6

The values change their sign in each step and decrease toward 0. The method is stable, because 0.2 is less than 0.25. The exact solution stays positive, so the values are not accurate.

6. A method has the global error 0.008 with the step size h and the global error 0.002 with the step size h/2. What is the order of the method?

0.008/0.002 = 4the error is divided by 4 when h is divided by 24 = 2²the factor is 2 to the power pp = 2the order

Python Practice

Step 1. The local error

The function ex below is the exact solution of the example. The code makes one step of the method of Euler from the starting point with t = 0 and y = 1, and prints the error of this step and h².

Python

The local error is 0.00967, close to 0.01. Now use h = 0.05. The local error should be 0.00246, about 4 times smaller.

Python

Step 2. The global error

The function euler runs the method from t = 0 to t = 1 with n steps and returns the last value. The code prints the global error for 10 steps and the error divided by h.

Python

The error is 0.038402, and the error divided by h is 0.384. Now use 80 steps. The error should be 0.004623, and the error divided by h should be 0.370.

Python

Step 3. The order from two runs

The code below divides the error of a run with n steps by the error of a run with 2n steps. For a method of the order 1, the quotient is close to 2.

Python

The quotient is 2.044. Now use n = 100. The quotient should be 2.004, closer to 2.

Python

Step 4. The estimate of the error and the corrected value

The code below runs the method with 10 steps and with 20 steps. It prints the estimate of the error of Part 3 and the corrected value. It does not use the exact solution.

Python

The estimate is 0.019615, and the corrected value is 0.736587. Now use n = 50, which compares 50 steps with 100 steps. The corrected value should be 0.735790. The exact value is 0.735759.

Python

Step 5. An unstable step size

The code below makes 50 steps of the method for the equation of Part 4, with the step size 0.11.

Python

The value is about 9100, and the exact solution is nearly 0. Now use h = 0.09, which satisfies the condition for stability. The value should be 0.000014.

Python

Quiz

This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.

Choose how your answers are checked

1. The step size of the method of Euler is divided by 2. What happens to the local error of one step?

2. A run of the method of Euler with h = 0.2 has the global error 0.06 at t = 4. Estimate the global error at t = 4 for h = 0.05.

3. The method of Euler gives the value Y₁ = 1.84 with the step size h and the value Y₂ = 1.90 with the step size h/2. Find the estimate of the error of Y₂ and the corrected value.

4. For which step sizes is the method of Euler stable for the equation y′ = −50y?

5. For y′ = t − y with y(0) = 1, find the value y₂ of the method of Euler with h = 0.1.

Next: Topic 7.2, Runge-Kutta Methods