Euler's Method
Euler's Method
For many of the differential equations we need to solve in the real world, there is no "nice" algebraic
solution. That is, we can't solve it using the techniques we have met in this chapter (separation of
variables, integrable combinations, or using an integrating factor), or other similar means.
As a result, we need to resort to using numerical methods for solving such DEs. The concept is similar
to the numerical approaches we saw in an earlier integration chapter (Trapezoidal Rule, Simpson's Rule
and Riemann Sums).
Even if we can solve some differential equations algebraically, the solutions may be quite complicated
and so are not very useful. In such cases, a numerical approach gives us a good approximate solution.
We are trying to solve problems that are presented in the following way:
𝑑𝑦
= 𝑓(𝑥, 𝑦); 𝑎𝑛𝑑
𝑑𝑥
Where, 𝑓(𝑥, 𝑦) is some function of the variables x, and y that are involved in the problem.
𝑑𝑦 𝑦
(𝑎) =6−2
𝑑𝑥 𝑥
𝑦(3) = 1
𝑑𝑦 𝑦𝐼𝑛𝑦
(𝑏) =
𝑑𝑥 𝑥
𝑦(2) = 𝑒
𝑑𝑦 50𝑥 2 − 10𝑦
(𝑐) =
𝑑𝑥 3
𝑦(0) = 0
Let's now see how to solve such problems using a numerical approach.
Euler's Method
Euler's Method assumes our solution is written in the form of a Taylor's Series.
This gives us a reasonably good approximation if we take plenty of terms, and if the value of is
reasonably small.
𝑑𝑦
The last term is just ‘h’ times our 𝑑𝑥 expression, so we can write Euler's Method as follows:
We start with some known value for y , which we could call y0 . It has this value when x = x0. (We
make use of the initial value (x0 , y0) .)
The result of using this formula is the value for y , one h step to the right of the current value. Let's call
it y1. So, we have:
𝑦1 ≈ 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 )
where
Next value: To get the next value 𝑦2 , we would use the value we just found for 𝑦1 as follows:
𝑦2 ≈ 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )
Where
𝑦2 is the next estimated solution value;
𝑥1 = 𝑥0 + ℎ; 𝑎𝑛𝑑
The right-hand side of the formula above means, "start at the known value, then move one step ‘h’ units
𝑑𝑦
to the right in the direction of the slope at that point, which is 𝑑𝑥 = 𝑓(𝑥, 𝑦). We will arrive at a good
approximation to the curve's y-value at that new point."
We'll do this for each of the sub-points, apart, from some starting value 𝑥 = 𝑎 to some finishing value,
𝑥 = 𝑏, as shown in the graph below.
Example: Euler's Method
Let's solve example (b) from above. We had the initial value problem:
𝑑𝑦 𝑦 𝐼𝑛 𝑦
=
𝑑𝑥 𝑥
𝑦(2) = 𝑒
Step 1
We'll start at the point (𝑥0 , 𝑦0 ) = (2, 𝑒) and use step size of ℎ = 0.1 and proceed for 10 steps. That is,
we'll approximate the solution from t =2 to t = 3 for our differential equation. We'll finish with a set of
points that represent the solution, numerically.
We already know the first value, when 𝑥0 = 2, which is 𝑦0 = 𝑒 (the initial value).
We now calculate the value of the derivative at this initial point. (This tells us the direction to move.)
𝑑𝑦 𝑒 𝐼𝑛 𝑒 𝑒
= 𝑓(2, 𝑒) = = ≡ 1.3591409
𝑑𝑥 2 2
This means the slope of the line from t =2 to t =2.1 is approximately 1.3591409.
Step 2
Now, for the second step, (since ℎ = 0.1 , the next point is 𝑥 + ℎ = 2 + 0.1 = 2.1 ), we substitute what
we know into Euler's Method formula, and we have:
𝑒
𝑦1 = 𝑦(2.1) ≈ 𝑒 + 0.1 ( ) = 2.8541959
2
This means the approximate value of the solution when x = 2.1 is 2.8540959.
𝑑𝑦 2.8541959 𝐼𝑛 2.8541959
= 𝑓(2.1, 2.8541959) = = 1.4254536
𝑑𝑥 2.1
This means the slope of the approximation line from 𝑥 = 2.1 to 𝑥 = 2.2 is 1.42. So, it's a little bit
steeper than the first slope we found.
Step 3
Now we are trying to find the solution value when 𝑥 = 2.2 . We substitute our known values:
2.99664126 𝐼𝑛 2.99664126
𝑓(2.2, 2.99664126) = = 1.49490457
2.2
This means the slope of the approximation line from 𝑥 = 2.2 to 𝑥 = 2.3 is 1.49490456. So, it's a little
steeper than the first 2 slopes we found.
Step 4
Now we are trying to find the solution value when 𝑥 = 2.3. We substitute our known values:
Subsequent Steps
Of course, most of the time we'll use computers to find these approximations. I used a spreadsheet to
obtain the following values. Don't use your calculator for these problems - it's very tedious and prone
to error. You could use an online calculator or google search.
𝑑𝑦
(There's no final 𝑑𝑥 value because we don't need it. We've found all the required y values.)
This question actually is easy to solve algebraically, and we did it back in the Separation of Variables
section. (It was Example 7.)
Our solution was 𝑦 = 𝑒 𝑥⁄2. In the next graph, we see the estimated values we got using Euler's Method
(the dark-coloured curve) and the graph of the real solution 𝑦 = 𝑒 𝑥⁄2 in magenta (pinkish). We can see
they are very close.
In this case, the solution graph is only slightly curved, so it's "easy" for Euler's Method to produce a
fairly close result.
4.4816890703 − 4.4180722576
= 1.42%
4.4816890703
Exercise
The following question cannot be solved using the algebraic techniques we learned earlier in this chapter,
so the only way to solve it is numerically.
𝑑𝑦
= sin(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥
𝑦(0) = 4
𝑢𝑠𝑒 ℎ = 0.1
Answer
Step 1
We start at the initial value (0,4) and calculate the value of the derivative at this point. We have:
𝑑𝑦
= 𝑠𝑖𝑛(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥
= sin(0 + 4) − 𝑒 0
= −1.75680249531
We substitute our starting point and the derivative we just found to obtain the next point along.
𝑦(0.1) ≈ 4 + 0.1(−1.75680249531)
≈ 3.82431975047
Step 2
Now we need to calculate the value of the derivative at this new point (0.1, 3.82431975047). We have:
𝑑𝑦
= sin(𝑥 + 𝑦) − 𝑒 𝑥
𝑑𝑥
= −1.8103864498
Once again, we substitute our current point and the derivative we just found to obtain the next point
along.
≈ 3.64328110549
We proceed for the required number of steps and obtain these values:
Here's the graph of this solution.
In the next section, we see a more sophisticated numerical solution method for differential equations,
called the Runge- Kutta Method.