Euler s Method for Approximating Solution Curves As you may have begun to suspect at this point, time constraints will allow us to learn only a few of the many known methods for solving differential equations. In other words, while this class will give you the ability to solve many equations, there will be many more that you cannot solve. In fact, even if you were familiar with every known solution method, there would still be differential equations that you would be unable to solve because of the limitations of integration techniques. For example, since we cannot evaluate the integral e x2 dx, we cannot solve the equation dx = ex2. For this reason, it is helpful to have numerical methods for approximating solutions; in this and the next two sections, we will learn several such numerical techniques. Our first technique is Euler s Method. Before discussing the method in general, let s illustrate the ideas behind the method using a simple example. As a first example of implementing a numerical solution technique, let s begin with the initial value problem y = 1 + y, y(0) = 1. Of course, we don t really need a numerical method to solve this equation; since it is separable, it is quite easy to solve without approximation. Let s go ahead and find a solution curve using the methods we are alrea comfortable with, so that we can compare the exact solution to a numerical approximation. Rewriting the equation as 1 + y = dx, it is clear that we can solve by integrating both sides. Since 1 + y = dx, and our solution is given by 1 + y = ln 1 + y, dx = x + C, ln 1 + y = x + C or y = e x e C 1. We can solve for C using the initial condition y(0) = 1: 1 = y(0) = e 0 e C 1 = e C 1 1
so that e C = 2. Thus the solution curve is y = 2e x 1, graphed below (and in the sequel) in red: Solution curve to the differential equation y = 1 + y. Now pretend for a moment that we did not know how to solve the initial value problem y = 1 + y, y(0) = 1, but still wished to understand what the solution curve looks like. At this point, we have very little information to go on: we know that the curve must pass through the point (1, 0), and we know that the slope of a tangent line to the curve at any point (x, y) is y = 1 + y. From this data, we need to extrapolate the shape of the curve. To make the jump from our bit of data to a guess at the curve s shape, we will go back to an idea that we have seen several times in calculus: near the point of tangency, a tangent lines value is an excellent approximation to the value of the curve, as illustrated in the graph below: The curve y = 2e x 1 and its tangent line at (0, 1). The solution curve (which we are pretending we don t alrea know!) and its tangent line at (0, 1) are very close together near the point (0, 1). For example, compare the curve and its tangent line at x = 1/2: 2
The points are quite close in height, so we could certainly use the tangent s height at x = 1/2 to approximate the solution curve s height at x = 1/2. Now this is a particularly useful idea since we have everything we need to determine the approximating point on the tangent line since we have a point on the tangent line (the point (0, 1)!), and since we know the slope of the curve at the point (0, 1) (again, since y = y + 1, the slope is y = 2), filling in the formula y y 0 = m(x x 0 ) or y = m(x x 0 ) + y 0 for a tangent line is simple. The tangent line has equation y = 2x + 1, and y(1/2) = 2, so the point highlighted above on the tangent line is (1/2, 2). The point (1/2, 2) now becomes the first approximation on our approximation curve. For later use, we will think of y = 1 + y as f(x, y) = 1 + y, and instead of writing y, we will write f(x, y). Let s keep track of the data that we ve collected; specifically, we should write down the points that we are using as approximations for the curves value, as well as the data that we need to continue the calculations: i f(x i, y i ) x i y i 1 1/2 2 The x and y columns give the coordinates of points of our approximation. In the first row, we have the point (x 0, y 0 ) = (0, 1), which we know to be on the curve. In the second row, the point (x 1, y 1 ) = (1/2, 2) appears as our first approximation. So far, we have approximated the red curve with the small blue line segment below: 3
Let s add another point to our approximation using the same process. We are assuming that the solution curve y passes through the point (x 1, y 1 ) = (1/2, 2). As before, we will begin by drawing a tangent line to the curve using the fact that y = f(x, y) gives us slopes of tangent lines: Again, the tangent line at this point should be close to the value for the actual solution y. As before, let s move away from this point in the x direction by our step size, h = 1/2, and determine the tangent line s height at x = 1 = 2h, as indicated in the graph below: We will use the point marked above on the tangent line as an approximation for the actual point (1, y(1)) on the curve. 4
Since the slope m of a tangent line to the curve at the point (x 1, y 1 ) is just f(x 1, y 1 ), we might wish to rewrite the formula y = m(x x 1 ) + y 1 for this line as y = f(x, y)(x x 1 ) + y 1 with x 1 = 1/2, y 1 = 2, and f(x 1, y 1 ) = 1+2 = 3. We want to calculate the height y 2 of this tangent line at x = x 2 = 1, which is Continuing our table, we add the third row: i f(x n, y n ) x i y i 1 3 1/2 2 2 1 7/2 y 2 = 3(x 2 1/2) + 2 = 3(1 1/2) + 2 = 7/2. The table now indicates that the second approximation point on our curve is (x 2, y 2 ) = (1, 7/2). Adding this third point to the graph yields the following approximation curve, graphed in blue: Now this process is going to get tedious, but a clear pattern is emerging. To get the fourth row of data, we will need to fill in x 3 and y 3. Using the same step size h = 1/2, we see that x 3 = 3/2 = 3h. To get y 3, we again revert to the formula for a line and note that the line is tangent to the curve at (x 2, y 2 ) = (1, 7/2), with slope f(x 2, y 2 ) = 9/2; so the equation for this line is y = f(x 2, y 2 )(x 1) + y 2 = 9/2(x 1/2) + 7/2; calculating the height y 3 of the line at x = x 3 gives us Continuing the table, we have: i f(x n, y n ) x i y i 1 3 1/2 2 2 9/2 1 7/2 3 3/2 23/4 y 3 = 9/2(x 3 1/2) + 7/2 = 9/2(1 1/2) + 7/2 = 23/4. 5
Again, the table now tells us that the third approximation point on our approximation curve is (x 3, y 3 ) = (3/2, 23/4). Adding this point to the approximation curve, we get the graph below: We should now be able to calculate the fourth point on our approximation curve without too much effort; using the pattern established above, we have y 4 = f(x 3, y 3 )(x 4 x 3 ) + y 3 = 27 4 (2 3/2) + 23 4 = 73 8 The approximation point (x 4, y 4 ) = (2, 73/8) is added below: We can follow the same pattern to generate any number of point on the approximation curve. The nth approximation point can be found on the nth line below: 6
i f(x n, y n ) x i y i 1 3 1/2 2 2 9/2 1 7/2 3 27/4 3/2 23/4 4 81/8 2 73/8. n 1 + y n n 2 f(x n, y n )h + y n 1 I used Mathematica to generate the graph below, which iterates the process described above for a total of 12 approximations: Our approximating curve is better than nothing (assuming that we were unable to solve the original equation), but it is clear from the graph that it truly is an approximation. This naturally leads to the question: How can we make the approximation better? One possibility is to make our step size smaller. The less we move away from the point of tangency, the better the tangent line is at approximating the curve. The table below computes the Euler s method approximation points with step size h = 1/10 (significantly smaller than our previous step size of 1/2): i f(x n, y n ) x i y i 1 11/5 1/10 6/5 2 121/50 1/5 71/50 3 1331/500 3/10 831/500 4 14641/5000 2/5 9641/5000. n 1 + y n n 10 f(x n, y n )h + y n 1 Compare the graph of the approximation curve generated with h = 1/10 to the actual solution: 7
Approximation to solution curve, smaller step size. It is clear that a smaller step size produced a much better approximation curve. We summarize Euler s method for approximating a solution curve to the initial value problem y = f(x, y), y(x 0 ) = y 0 below: Choose step size h Iterate the process of choosing points on the approximation curve: 1. Calculate the (n + 1)st approximation on the approximation curve using the formula y n+1 = y n + h f(x n, y n ), x n+1 = x 0 + (n + 1)h. 2. Connect the points (x n, y n ) and (x n+1, y n+1 ) with a line segment. As noted above, Euler s method produces an approximation to the actual solution curve of a given differential equation. Since the approximation curve is not the actual solution curve, we say that Euler s method produces an error. For example, in our first set of calculations for the approximation to the solution of the initial value problem y = 1 + y, y(0) = 1, we ended up with the following approximation curve after 20 applications of Euler s method: 8
Compare this to the actual solution curve, graphed below in red: The error produced after 10 steps is marked above, and is quite significant. The following theorem tells us how much error to expect Euler s method to produce, based on the chosen step size: Theorem 1. Suppose that the initial value problem dx = f(x, y), y(x 0) = y 0 has a unique solution y(x) on the closed interval [a, b] with a = x 0, and assume that y(x) has a continuous second derivative on [a, b]. Suppose that the Euler s method approximations to the actual values y1, y2, y3,..., y k y(x 1 ), y(x 2 ), y(x 3 ),... y(x k ), are computed using step size h. Then there is a constant C so that y n y(x n ) Ch for each n, that is the nth approximation y n is no farther than Ch from the actual value y(x n ). The theorem simply states that, under certain circumstances, there is a constant C so that the total error in the nth step of Euler s method is no more than Ch, i.e. a constant multiple of the step size. This confirms our previous suspicion that step size also reduces the error. 9