Differential Equations / Unit 1, Differential Equations and Their Solutions / Topic 1.3
Unit 1. Differential Equations and Their Solutions
The method of Euler turns a direction field into numbers. It starts at the initial condition and follows the slopes in short straight steps. The result is a table of approximate values of the solution. This topic covers the formula of the method, a complete example, the error of the method, and the choice of the step size.
You need Topics 1.1 and 1.2 for this topic.
An initial value problem gives an equation and a starting point.
y′ = f(t, y) with y(t₀) = y₀At the starting point (t₀, y₀), the slope of the solution is f(t₀, y₀). Over a short time h, the solution curve stays close to its tangent line. So the method moves along the tangent line for the time h and takes the point that it reaches as the next point of the solution.
t₁ = t₀ + hthe time grows by the step size hy₁ = y₀ + h f(t₀, y₀)the value changes by the slope times hAt the new point, the method calculates a new slope and takes the next step. The number h is called the step size.
The method of Euler. Starting from (t₀, y₀), repeat these two lines for n = 0, 1, 2, and so on.
yn+1 = yₙ + h f(tₙ, yₙ)the new valuetn+1 = tₙ + hthe new timeThe number yₙ is an approximation of the exact value y(tₙ). The method needs only the equation and the starting point. It does not need a formula for the solution.
Use the method with the step size h = 0.5 to find approximate values of the solution of y′ = t − y with y(0) = 1, up to the time t = 2. Here f(t, y) = t − y, t₀ = 0, and y₀ = 1.
From Topic 1.2, the general solution of this equation is y = t − 1 + Ce−t. The initial condition gives the constant.
y(0) = 0 − 1 + C = C − 1substitute t = 0C − 1 = 1the initial condition y(0) = 1C = 2add 1 to both sidesy = t − 1 + 2e−tthe exact solutionThe table compares the values of the method with the exact values, rounded to four decimal places.
| n | tₙ | yₙ from the method | Exact value y(tₙ) | Error |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 |
| 1 | 0.5 | 0.5 | 0.7131 | 0.2131 |
| 2 | 1 | 0.5 | 0.7358 | 0.2358 |
| 3 | 1.5 | 0.75 | 0.9463 | 0.1963 |
| 4 | 2 | 1.125 | 1.2707 | 0.1457 |
The values of the method follow the exact solution, but they are not accurate with this large step size.
Try it: the steps of the method of Euler
The purple curve is the exact solution with y(0) = 1. The green points are the values of the method of Euler, joined by straight lines. The menu selects the equation, and the slider sets the step size h.
A smaller step size keeps each step closer to the solution curve. The table shows the value of the method at t = 2 for the example of Part 2, with five step sizes. The exact value is 1.2707.
| Step size h | Number of steps | Value at t = 2 | Error |
|---|---|---|---|
| 0.5 | 4 | 1.1250 | 0.1457 |
| 0.25 | 8 | 1.2002 | 0.0704 |
| 0.1 | 20 | 1.2432 | 0.0275 |
| 0.05 | 40 | 1.2570 | 0.0136 |
| 0.01 | 200 | 1.2680 | 0.0027 |
The error at a fixed time is roughly proportional to the step size. When h is divided by 2, the error is divided by about 2. When h is divided by 10, the error is divided by about 10. A method with this property is called a first order method.
A smaller step size costs more work, because the number of steps is the length of the time interval divided by h. One more correct decimal place needs about ten times as many steps. Topic 7.1 studies the error of the method, and Topic 7.2 teaches methods that reach the same accuracy with far fewer steps.
For the equation y′ = y with y(0) = 1, the exact solution is y = et. Here f(t, y) = y, and the steps of the method have a simple form.
yn+1 = yₙ + h yₙ = (1 + h)yₙeach step multiplies the value by 1 + hy₁ = (1 + h)y₀ = 1 + hthe first step, with y₀ = 1y₂ = (1 + h)y₁ = (1 + h)²the second stepyₙ = (1 + h)ⁿafter n stepsTo reach the time t = 1 in n steps, the step size is h = 1/n. The value of the method at t = 1 is then (1 + 1/n)ⁿ, and the exact value is e.
| Number of steps n | Step size h | (1 + 1/n)ⁿ |
|---|---|---|
| 10 | 0.1 | 2.5937 |
| 100 | 0.01 | 2.7048 |
| 1000 | 0.001 | 2.7169 |
The values approach e = 2.7183 as n grows. This is the limit that defines the number e in calculus, and the method of Euler produces it.
For some equations, a large step size gives values that do not follow the solution at all. The equation y′ = −10y with y(0) = 1 has the exact solution y = e−10t, which decreases quickly toward 0. The steps of the method are
yn+1 = yₙ + h(−10yₙ)the formula of the method, with f(t, y) = −10yyn+1 = (1 − 10h)yₙeach step multiplies the value by 1 − 10h| Step size h | Factor 1 − 10h | Values y₀, y₁, y₂, y₃ | Behavior |
|---|---|---|---|
| 0.05 | 0.5 | 1, 0.5, 0.25, 0.125 | Decreases toward 0, like the solution |
| 0.25 | −1.5 | 1, −1.5, 2.25, −3.375 | Changes its sign in each step and grows |
With h = 0.25, the tangent line at the first point reaches far below zero before the step ends, and each later step makes the error larger. The values grow without limit, and the solution goes to 0. The method is called unstable for this step size. When the values of the method change their sign in each step or grow quickly, repeat the calculation with a smaller step size and compare the results.
By hand, the method is practical for a few steps. A computer takes thousands of steps in a fraction of a second, and the Python Practice of this topic shows how. Numerical methods of this kind are the usual way to solve the differential equations of science and engineering, because most of them have no solution formula.
| Idea | Statement |
|---|---|
| One step | yn+1 = yₙ + h f(tₙ, yₙ) and tn+1 = tₙ + h |
| Step size | The time h between two points of the method |
| Error | Roughly proportional to h at a fixed time |
| Cost | The number of steps is the length of the interval divided by h |
| y′ = y | The method gives (1 + h)ⁿ, which approaches et |
| Instability | A step size that is too large can give values that grow while the solution decreases |
Work each problem on paper first. Then open the answer to check your work.
f(t₀, y₀) = 2(3) = 6the slope at the starty₁ = 3 + 0.1(6) = 3.6the new valuet₁ = 0 + 0.1 = 0.1the new time
f(t₀, y₀) = 0 + 1 = 1the slope at the point (0, 1)y₁ = 1 + 0.5(1) = 1.5the first new valuet₁ = 0.5the first new timef(t₁, y₁) = 0.5 + 1.5 = 2the slope at the point (0.5, 1.5)y₂ = 1.5 + 0.5(2) = 2.5the second new valuet₂ = 1the second new time
yn+1 = yₙ + 0.5(−yₙ) = 0.5yₙeach step multiplies the value by 0.5y₁ = 0.5(8) = 4at t = 0.5y₂ = 0.5(4) = 2at t = 1y₃ = 0.5(2) = 1at t = 1.5
The exact value is 8e−1.5, which is about 1.785.
0.1/0.02 = 5the step size is divided by 50.03/5 = 0.006the error is divided by about 5
The calculation with h = 0.02 needs 5 times as many steps.
yn+1 = yₙ + h(−4yₙ) = (1 − 4h)yₙthe factor is 1 − 4h1 − 4(0.1) = 0.6the factor for h = 0.11 − 4(0.6) = −1.4the factor for h = 0.6
With h = 0.1 the values decrease toward 0, like the solution. With h = 0.6 the values change their sign in each step and grow, so the method is unstable.
f(0, 0) = 9.8 − 0.2(0) = 9.8the acceleration at the startv₁ = 0 + 1(9.8) = 9.8the velocity after 1 secondf(1, 9.8) = 9.8 − 0.2(9.8) = 7.84the acceleration at the new pointv₂ = 9.8 + 1(7.84) = 17.64the velocity after 2 seconds
The values are in meters per second. The acceleration decreases as the velocity grows, as the direction field of Topic 1.2 shows.
The code below takes the first step of Part 2. The line y = y + h * slope is not an equation. Python first calculates the right side with the old value of y, and then it stores the result under the name y. After this line, y holds the new value. The line for t works in the same way.
Python
The result is the point (0.5, 0.5) of Part 2. Now change the step size to 0.1. The new point should be (0.1, 0.9).
Python
A loop repeats lines of code. The line for n in range(4): says that the lines under it are run 4 times. The lines that belong to the loop are indented, which means that they start with four spaces. The code below takes the four steps of Part 2 and prints the point after each step.
Python
The four lines of the result are the rows of the table in Part 2. The last value is 1.125. Now reach the time t = 2 with the step size 0.25, which needs 8 steps. The last value should be about 1.2002.
Python
The exact solution of the example is y = t − 1 + 2e−t. The code below stores the number of steps under the name steps and calculates the step size from it. The print instruction is outside the loop, because it is not indented, so it runs once after the last step. It shows the value of the method at t = 2, the exact value, and the error.
Python
The error is about 0.1457, as in Part 3. Now use 200 steps. The step size is then 0.01, and the error should be about 0.0027.
Python
A loop can contain another loop. In the code below, the outer loop takes the numbers of steps 4, 8, 16, and 32 from a list, one after the other. For each number, the inner loop does the whole calculation of Step 3. The lines of the inner loop are indented twice. After each calculation, the code prints the number of steps, the step size, and the error.
Python
Each line has twice as many steps as the line before it, and about one half of its error. Now add the number 64 at the end of the list. The new last line should show an error of about 0.0085.
Python
The code below uses the method for y′ = y with y(0) = 1 and reaches the time t = 1 in 10 steps, as in Part 4. It prints the value of the method and the exact value e, which is typed as np.exp(1).
Python
The value of the method is 2.5937, and e is 2.7183. Now use 1000 steps. The value should be about 2.7169.
Python
The code below takes six steps for the equation y′ = −10y of Part 5 with the step size 0.25, and it prints the value after each step.
Python
The values change their sign in each step and grow, although the exact solution decreases toward 0. Now change the step size to 0.05. The values should be 0.5, 0.25, 0.125, and so on.
Python
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. Take one step of the method of Euler for y′ = 2y with y(0) = 1 and h = 0.1. Find y₁.
f(t₀, y₀) = 2(1) = 2the slope at the starty₁ = 1 + 0.1(2) = 1.2the new value
2. Take two steps of the method of Euler for y′ = t + y with y(0) = 1 and h = 0.5. Find y₂.
f(t₀, y₀) = 0 + 1 = 1the slope at the point (0, 1)y₁ = 1 + 0.5(1) = 1.5the first new value, at t = 0.5f(t₁, y₁) = 0.5 + 1.5 = 2the slope at the point (0.5, 1.5)y₂ = 1.5 + 0.5(2) = 2.5the second new value
3. The step size of the method of Euler is divided by 2. What happens to the error at a fixed time?
The error of the method at a fixed time is roughly proportional to the step size. One half of the step size gives about one half of the error, with twice as many steps.
4. Along which line does one step of the method of Euler move?
The method calculates the slope at the current point and moves along the straight line with that slope for the time h. This line is the tangent line of the solution curve through the current point.
5. The method of Euler is used for y′ = −10y with y(0) = 1 and h = 0.25. How do the values behave?
yn+1 = yₙ + 0.25(−10yₙ)the formula of the methodyn+1 = −1.5yₙeach step multiplies the value by −1.5The values are 1, −1.5, 2.25, −3.375, and so on. The method is unstable for this step size.