Video: Euler’s Method

In this video, we will learn how to use Euler’s method to approximatesolutions to differential equations.

15:27

Video Transcript

In this lesson, we’ll learn how to use Euler’s method to approximate solutions to differential equations. When we can’t solve a differential equation by analytical methods, we can use what are called numerical methods. From a given starting point, we use it to find repetitive process to approximate a solution to our differential equation. Euler’s method is one such process. We’ll begin by reminding ourselves of the meanings of some of the terms that we’ll use. We’ll then look at how Euler’s method is formulated and go on to see how it works with some examples.

Remember that a differential equation is an equation containing one or more derivatives. The first-order differential equation contains only the first derivative d𝑦 by d𝑥. And for an unknown function 𝑦, we have the slope of 𝑦 in terms of the function 𝑓, which can be a function of 𝑥 and 𝑦, a function of 𝑥, or a function of 𝑦. And we might be asked to solve the differential equation d𝑦 by d𝑥 is equal to 𝑓 of 𝑥, 𝑦 given the initial value 𝑦 at 𝑥 is equal to zero is 𝑦 zero. This means that our starting point is the point 𝑥 zero, 𝑦 zero. And we’re to use this to find the function 𝑦 of 𝑥. When we do this numerically, we use the point 𝑥 zero, 𝑦 zero to find the value of 𝑦 one, which we then use to find 𝑦 two with our differential equation and so on to 𝑦 𝑛. This gives us our approximation to the function 𝑦 of 𝑥.

Using Euler’s method, we do this by using a series of tangent lines to build up a picture of our solution. Since we’ll be using tangent lines, let’s keep our differential equation in mind but remind ourselves of some fact about straight lines. Suppose we have a straight line through the points 𝑥 zero, 𝑦 zero and 𝑥 one, 𝑦 one. The slope of this line 𝑚 is equal to 𝑦 one minus 𝑦 zero over 𝑥 one minus 𝑥 zero. Rearranging this we have 𝑦 one minus 𝑦 zero is equal to 𝑚 times 𝑥 one minus 𝑥 zero. This gives us 𝑦 one equal to 𝑦 zero plus 𝑚 times 𝑥 one minus 𝑥 zero. Now, if we go back to our differential equation, we know that the slope of 𝑦, d𝑦 by d𝑥, is equal to 𝑓 of 𝑥 𝑦 so that at the point 𝑥 zero, 𝑦 zero, the slope 𝑚 is equal to 𝑓 of 𝑥 zero, 𝑦 zero. And for our line through the points 𝑥 zero, 𝑦 zero and 𝑥 one, 𝑦 one, we have 𝑦 one equal to 𝑦 zero plus 𝑓 of 𝑥 zero, 𝑦 zero times 𝑥 one minus 𝑥 zero.

And now, if we call the distance between 𝑥 zero and 𝑥 one ℎ, we have 𝑦 one equal to 𝑦 zero plus ℎ times 𝑓 of 𝑥 zero, 𝑦 zero. So we can calculate the value of 𝑦 one from knowing 𝑦 zero, ℎ, and 𝑓 of 𝑥 zero 𝑦 zero. Let’s see how this works on a graph of the function 𝑦. We have our starting point on the graph 𝑦 of 𝑥, which is 𝑥 zero, 𝑦 zero. We draw a tangent line to the curve at 𝑥 zero, 𝑦 zero. And we know that the slope of this line is 𝑓 of 𝑥 zero, 𝑦 zero. If we continue this line to where it meets the vertical with 𝑥 one, which is the distance ℎ from 𝑥 zero, this gives us the value 𝑦 one. Now, if we draw a tangent to the curve 𝑦 at the point 𝑥 one, 𝑦 one, this tangent has the slope 𝑓 of 𝑥 one, 𝑦 one. If this tangent then meets the vertical at 𝑥 two, which is the distance ℎ from 𝑥 one, we can find 𝑦 two, in terms of 𝑦 one, ℎ, and 𝑓 of 𝑥 one, 𝑦 one.

If we continue in this way for a specified number of steps 𝑛 up to 𝑥 𝑛, on a specified step size ℎ we find 𝑦 𝑛 is equal to 𝑦 𝑛 minus one plus ℎ times 𝑓 of 𝑥 𝑛 minus one 𝑦 𝑛 minus one. And in this way, we find an approximation to 𝑦 of 𝑓 𝑥 which is a solution to the differential equation. It’s important to remember that we’re actually approximating a solution to the given differential equation. If our step size is quite large, our approximation might be quite far away from the actual solution function 𝑦 of 𝑥. We can increase the accuracy of our solution by decreasing the step size. Now, let’s see how this works with an example.

Consider the initial value problem 𝑦 prime is four 𝑥 minus three 𝑦 where 𝑦 at 𝑥 equal to zero is negative one. Use Euler’s method with 𝑛 equal to five steps on the closed interval zero one to find the value of 𝑦 at 𝑥 is equal to one.

We’ve actually been given a differential equation 𝑦 prime is equal to four 𝑥 minus three 𝑦 and an initial value 𝑦 at 𝑥 is equal to zero is negative one. This means that our starting point for Euler’s method is the point 𝑥 zero, 𝑦 zero which is equal to zero, negative one. We also know that we have five steps and that our closed interval zero, one means that zero is less than or equal to 𝑥 is less than or equal to one. So we have 𝑛 equal to five and zero less than or equal to 𝑥 less than or equal to one.

We’re asked to use Euler’s method to find the value of 𝑦 at 𝑥 is equal to one. To do this, the first thing we need to do is to find the value of ℎ. That’s our step size. Now, ℎ is the interval width divided by the number of steps, in our case, the interval where there’s a maximum 𝑥 value one minus the minimum 𝑥 value zero which is one. The number of steps is five. So our step size is one over five. Let’s just sketch our Interval so that we can refer to it throughout our calculations. Our first 𝑥 value is zero, which is 𝑥 zero. Our step size is one over five, which is 0.2. So our next point 𝑥 one is 0.2. Our next 𝑥 value 𝑥 two is 0.4, 𝑥 three is 0.6, 𝑥 four is 0.8, and 𝑥 five is one.

And remember, we’re being asked to calculate the value of 𝑦 at 𝑥 is equal to one. So that’s 𝑦 of 𝑥 five, which is 𝑦 five. So we’re going to use Euler’s method to calculate 𝑦 five. We can’t go directly to 𝑦 five because the only value we have is 𝑥 zero, 𝑦 zero. So we start at this point and calculate 𝑦 one, 𝑦 two, then 𝑦 three, then 𝑦 four, and then 𝑦 five. So to use the formula, we need to know the value of 𝑥 zero, 𝑦 zero, which is zero, negative one. We need to know ℎ, which is 0.2, and we need to know what the function 𝑓 of 𝑥, 𝑦 is. In our differential equation, 𝑦 prime, which is d𝑦 by d𝑥, is equal to four 𝑥 minus three 𝑦. So 𝑓 of 𝑥 𝑦, in our case, is four 𝑥 minus three 𝑦.

We know that 𝑦 zero is equal to negative one. And we can use this to find 𝑦 one. And in the formula, if 𝑛 is equal to one, then 𝑛 minus one is equal to zero so that 𝑦 one is equal to 𝑦 zero plus ℎ times 𝑓 of 𝑥 zero, 𝑦 zero. We know that 𝑦 zero was negative one and that ℎ is 0.2. So we need to find 𝑓 of 𝑥 zero, 𝑦 zero. In our differential equation, 𝑓 of 𝑥 zero, 𝑦 zero is four 𝑥 zero minus three 𝑦 zero. And that’s equal to four times zero minus three times negative one, which is equal to three, so that 𝑦 one is equal to negative one plus 0.2 times three, which is negative 0.4. Now, we can use 𝑦 one to calculate 𝑦 two.

We know that 𝑦 one is equal to negative 0.4. We know that ℎ is 0.2. So we need to work out 𝑓 of 𝑥 one, 𝑦 one. And that’s equal to four 𝑥 one minus three 𝑦 one. And since 𝑥 one is 0.2, that’s four times 0.2 minus three times negative 0.4, which is 0.8 plus 1.2 which is two. So 𝑦 two is equal to negative 0.4 plus 0.2 times two which is actually zero. Now, if we put 𝑛 equal to three in our formula, 𝑦 three is equal to 𝑦 two plus ℎ times 𝑓 of 𝑥 two 𝑦 two. We know that 𝑦 two is equal to zero and ℎ is 0.2. So we need to work out 𝑓 of 𝑥 two 𝑦 two. And that’s equal to four 𝑥 two minus three 𝑦 two. And since 𝑥 two is 0.4, that’s four times 0.4 minus three times zero, which is 1.6. So we have 𝑦 three equal to zero plus 0.2 times 1.6, which is 0.32.

Now, with 𝑛 equal to four, we have 𝑦 four is equal to 𝑦 three plus ℎ times 𝑓 of 𝑥 three, 𝑦 three. 𝑓 of 𝑥 three 𝑦 three is four 𝑥 three minus three 𝑦 three. So we have four times 0.6 minus three times 0.32 which is 1.44, so that 𝑦 four is equal to 0.32 plus 0.2 times 1.44 and that’s 0.608. And finally with 𝑛 equal to five in our formula, we have 𝑦 five equal to 𝑦 four plus ℎ times 𝑓 of 𝑥 four 𝑦 four. 𝑓 of 𝑥 four 𝑦 four is equal to four 𝑥 four minus three 𝑦 four. And that’s equal to four times 0.8 minus three times 0.608 which is 1.376 so that we have 𝑦 five equal to 0.608 plus 0.2 times 1.376. And that’s equal to 0.8832. And remember that it’s exactly 𝑦 five that we’re looking for because this is the value of 𝑦 at 𝑥 is equal to one, so that 𝑦 of one is 0.8832.

Now let’s plot our approximation to the function 𝑦, using the points that we found. The graph shown is a computer-generated solution of the differential equation 𝑦 prime is four 𝑥 minus three 𝑦 with initial value 𝑥 zero, 𝑦 zero is zero, negative one. And these are the points that we found using Euler’s method to find an approximation to the solution. If we plot our points on the graph, we can see it’s a very good approximation to the computer-generated solution.

In our next example, we’ll look at a derivative or slope, which is a function of 𝑥 only. And then we’ll compare different solutions, which have used different step sizes for the approximations.

Consider the initial value problem 𝑦 prime is three 𝑥, where 𝑦 at 𝑥 is equal to zero is equal to one. Use Euler’s method with 𝑛 equal to five steps on the closed interval zero, one to find 𝑦 at 𝑥 is equal to one.

We’ve been given a differential equation 𝑦 prime is three 𝑥 so that 𝑦 prime, which is d𝑦 by d𝑥, is equal to three 𝑥. We have an initial value 𝑦 at 𝑥 is equal to zero is equal to one, which means that our starting point 𝑥 zero, 𝑦 zero is zero one. We have 𝑛 equals to five steps and the closed interval zero, one. This means that zero is less than or equal to 𝑥 is less than or equal to one. And we’re asked to use Euler’s method to find the value of 𝑦 at 𝑥 is equal to one. In order to use this formula, we need to know the value of ℎ, which is the step size. And that’s given by the interval width divided by the number of steps. In our case, the interval width is a maximum 𝑥 minus the minimum 𝑥 which is one minus zero divided by the number of steps which is five. That’s one over five, which is 0.2.

Let’s just sketch our interval, so we can refer back to it in our calculations. Since our step size is 0.2 and 𝑥 zero is equal to zero, 𝑥 one is equal to 0.2. Similarly, 𝑥 two is equal to 0.4, 𝑥 three is 0.6, and 𝑥 four is 0.8, and 𝑥 five, which is our maximum value is one. Remember, we’re trying to find the value of 𝑦 when 𝑥 is equal to one. And that’s 𝑦 of 𝑥 five. And we call that 𝑦 five. In order to use the formula, we need to know what our function 𝑓 is. And from our differential equation, we can see that d𝑦 by d𝑥 is equal to 𝑓 of 𝑥 is three 𝑥. So if this is a function of 𝑥 only, this means we can delete the second variable 𝑦 in our function 𝑓 in Euler’s formula, so that our formula is 𝑦 𝑛 is equal to 𝑦 𝑛 minus one plus ℎ times 𝑓 of 𝑥 𝑛 minus one, where 𝑓 of 𝑥 𝑛 is three 𝑥 𝑛. So we have everything we need to use the formula.

We know that 𝑦 zero is equal to one, so we can use the formula to calculate 𝑦 one. And that’s equal to 𝑦 zero plus ℎ times 𝑓 of 𝑥 zero. We know the value of 𝑦 zero, which is one, and we know the value of ℎ, which is 0.2. So we need to work out 𝑓 of 𝑥 zero. From our differential equation, that’s equal to three times 𝑥 zero, which is three times zero, which is zero so that 𝑦 one is equal to one plus 0.2 times zero, which is one. And we can use this in our formula to calculate 𝑦 two, which is equal to 𝑦 one plus ℎ times 𝑓 of 𝑥 one. And we need to work out 𝑓 of 𝑥 one. That’s equal to three times 𝑥 one from our differential equation. And from our interval, we know that 𝑥 one is equal to 0.2. So we have three times 0.2 is equal to 𝑓 of 𝑥 one, and that’s 0.6.

So 𝑦 two is equal to one plus 0.2 times 0.6 which is equal to 1.12. We use this to find 𝑦 three, which is 𝑦 two plus ℎ times 𝑓 of 𝑥 two, where 𝑓 of 𝑥 two is three times 𝑥 two and 𝑥 two is 0.4, so that 𝑓 of 𝑥 two is 1.2. 𝑦 three is then 1.12 plus 0.2 times 1.2, which is 1.36. We use this to calculate 𝑦 four which is 𝑦 three plus ℎ times 𝑓 of 𝑥 three and 𝑓 of 𝑥 three is three times 𝑥 three. From our interval, 𝑥 three is 0.6. So that’s three times 0.6, which is 1.8. And we have 𝑦 four equal to 1.36 plus 0.2 times 1.8, which is 1.72. Now, we use this in our final step to calculate 𝑦 five, where 𝑦 five is equal to 𝑦 four plus ℎ times 𝑓 of 𝑥 four which is three 𝑥 four. And since 𝑥 four is 0.8 from our interval, 𝑓 of 𝑥 four is three times 0.8, which is 2.4. So 𝑦 five is equal to 1.72 plus 0.2 times 2.4, which is 2.2. Remember that 𝑦 five is equal to 𝑦 at 𝑥 is equal to one, which we’ve just calculated as 2.2. So 𝑦 at 𝑥 is equal to one is 2.2.

In our example, we were given 𝑛 equal to five steps on the closed interval zero, one. This resulted in the step size of 0.2. From an initial value of 𝑥 zero, 𝑦 zero, which is equal to zero one, we calculated all the steps up to 𝑥 five, 𝑦 five and arrived at one, 2.2. The graph shown gives a computer-generated solution to the differential equation and our approximated solution with the five points that we calculated. Now, let’s see what happens if we decrease the step size. With 𝑛 equal to 10 in the step size of 0.1 now, we have five extra points. On our graph, we can see that the approximation with the smaller step size is closer to the computer-generated solution. So when the step size is smaller, the approximate solution is closer to the actual solution, although notice that we needed to do more iterations in our calculation.

Let’s summarize now what we’ve covered in Euler’s method. We’ve been looking at Euler’s method for first-order differential equations, which is a numerical method for solving first-order differential equations of the form d𝑦 by d𝑥 is 𝑓 of 𝑥, 𝑦 or d𝑦 by d𝑥 is 𝑓 of 𝑥 or d𝑦 by d𝑥 is 𝑓 of 𝑦. In order to solve, we’re given an initial value, which is 𝑦 at 𝑥 equal to 𝑥 zero. And that’s equal to 𝑦 zero, so that from our starting point 𝑥 zero, 𝑦 zero, we have 𝑛 steps in the interval 𝑥 zero to 𝑥 𝑛. We use the formula 𝑦 𝑛 is equal to 𝑦 𝑛 minus one plus ℎ times 𝑓 of 𝑥 𝑛 minus one 𝑦 𝑛 minus one to find successive values of 𝑦, in order to form an approximation to the solution 𝑦 of 𝑥. ℎ is the step size, which is the interval width divided by the number of steps. And we know that the smaller the step size ℎ, the more accurate the approximation. But this means more iterations will be necessary.

Nagwa uses cookies to ensure you get the best experience on our website. Learn more about our Privacy Policy.