Section 2.7 Euler s Method (Computer Approximation) Key Terms/ Ideas: Numerical method for approximating the solution of an IVP Linear Approximation; Tangent Line Euler Algorithm (the simplest approximation method)
We have seen in Section 1.1 that by drawing a direction field we can visualize qualitatively the behavior of solutions of a first order DE. When the grid is fine then we obtain a direction field that can convey a sense of the behavior of solutions for various initial conditions. For example, for DE we have direction field dy = y 2-2t dt For a first order DE we can sketch a direction field and visualize the behavior of solutions once we choose an initial value for example y(a) = k. This has the advantage of being a relatively simple process, even for complicated equations. However, direction fields do not lend themselves to quantitative computations or comparisons.
By choosing different initial conditions we can see approximately how some solutions behave. So we are really considering initial value problems. Initial condition x = -2, y = -1 Initial condition x = -1, y = -1 To sketch these solutions of the IVP a numerical method was used.
For quantitative approximations of an IVP we need to consider numerical approximation schemes. Such techniques generate approximate values for the solution of the IVP at a set of discrete values of independent variable t; t 0, t 1, t 2, etc. So the output from such numerical algorithms consists of a set of ordered pairs (t k, y k ) where y k is an approximation to the true value y(t k )of the solution at t k. (y k y(t k )) One algorithm that will allow you to estimate values of the solution y is given by Euler s Method sometimes called the tangent line method. (Euler (pronounced Oiler) lived in the 18th century is considered to be one of the greatest mathematicians who ever lived.) Observe that the direction field has many tangent line segments at successive values of t that almost touch each other. It takes only a bit of imagination to consider starting at a point specified by an initial condition and linking line segments for successive values of t in the grid, thereby producing a piecewise linear graph. Such a graph would provide an approximation to the solution of the IVP.
To see how Euler s method works, recall from calculus a section called Linear Approximation. In that section you did the following: Construct the tangent line to a differentiable function f(x) at a point (a, f(a)) and approximate values of the function at nearby values of x using the equation of the tangent line. Suppose we have the point (a, f(a)) and the slope of f(x) at this point is the value m. Then the tangent line is obtained using the point-slope method for the equation of a line. Tangent line is: y f(a) = m(x a) y = f(a) + m(x a). We can estimate the value of f(x) at x = a + Δx by computing f(a) + m(a + Δx a) = f(a) +m Δx. Euler s method uses this idea applied to an initial value problem as we illustrate next.
We start Euler s approximation to the IVP at the initial point (t 0, y 0 ) and use the fact that the slope of the exact solution at the initial point is the value of f(t 0, y 0 ) so the equation of the tangent line at the initial point is y y 0 = f(t 0, y 0 ) (t t 0 ). Rewrite this as y = y 0 + f(t 0, y 0 ) (t t 0 ). The tangent line is a good approximation to the actual solution curve on a short interval over which the slope of the solution does not change appreciably from its value at the initial point. Exact solution Thus, if t 1 is close enough to t 0, we can approximate the exact solution at t = t 1 by the value y 1 determined by substituting t 1 for t in the equation of the tangent line. Doing this we get y 1 = y 0 + f(t 0, y 0 ) (t 1 t 0 ). So far we have points (t 0, y 0 ) and (t 1, y 1 ). If we connect these points with a straight line we have a linear approximation to the exact solution φ(t) over interval [t 0, t 1 ]. linear approximation
To proceed further, we can try to repeat the process. Unfortunately, we do not know the value of the exact solution value at t 1. The best we can do is to use the approximate value y 1 instead. Thus we construct the line through (t 1, y 1 ) with the slope f(t 1, y 1 ). For a point t 2 close to t 1, we approximate the exact solution at t 2 using the line passing through (t 1, y 1 ) with slope f(t 1,y 1 ). We then compute y 2 = y 1 + f(t 1, y 1 ) (t 2 t 1 ) which approximates the exact solution at t 2. So now we have three points (t 0, y 0 ),(t 1, y 1 ), and (t 2, y 2 ). Using this process at the second step we are really approximating a new IVP; As along as the integral curve for the original IVP is not much different that than the integral curve for the new IVP, we can obtain an estimate of the solution of the original IVP. This is where some error creeps in. Thus we create a discrete sequence y n of approximations to the exact solution at the discrete points t 1, t 2, t 3, : where f k = f(t k,y k ) is the slope of the tangent line at t = t k for k =0, 1,, n.
The sequence of calculations generates the sequence of points To graph an Euler approximation, we plot the points (t 0, y 0 ), (t 1, y 1 ),, (t n, y n ), and then connect these points with line segments to provide a piecewise linear approximation to the solution of the original IVP. If the discrete values t 1, t 2, t 3, are equispaced we say the step size is a fixed value often denoted by h. For a fixed step size h = t k t k-1, for each value of k. Thus Euler s formula for equispacing becomes
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' i = f(t i,y i ) = f i 0 0 1 1 0.2 2 0.4 3 0.6 4 0.8 5 1.0 Slope computation y i+1 = y i + h f(t i,y i ) Estimate of soln at t i+1 Compute the slope at t 0 = 0 and use the fact that y 0 = y(0)= 1 in the Euler formula.
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' i = f(t i,y i ) = f i Slope computation y i+1 =y i + h f(t i,y i ) Estimate of soln at t i+1 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 2 0.4 3 0.6 4 0.8 5 1.0 y1 y0 f0 h 1 ( 3 0 0. 5) ( 0. 2) 1 2. 5( 0. 2) 1. 5 Substituted t = 0 and y = 1 into formula for f(t, y)
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i Slope computation y i+1 =y i + h f(t i,y i ) Estimate of soln at t i+1 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 2 0.4 3 0.6 4 0.8 5 1.0 y1 y0 f0 h 1 ( 3005. )( 0. 2) 1 2. 5( 0. 2) 1. 5 Compute the slope at t 1 = 0.2 and use the fact that we have the approximation y 1 = 1.5 to use in the Euler formula.
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 3 0.6 4 0.8 5 1.0 y1 y0 f0 h 1 ( 3 0 0. 5) ( 0. 2) 1 2. 5( 0. 2) 1. 5... y2 y1 f1 h 15. 3 2 0 2 0 5 15 ( 0. 2) 1. 87 Substituted t = 0.2 and y = 1.5 into formula for f(t, y)
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 3 0.6 4 0.8 5 1.0 y1 y0 f0 h 1 ( 3 0 0. 5) ( 0. 2) 1 2. 5( 0. 2) 1. 5... y2 y1 f1 h 15. 3 2 0 2 0 5 15 ( 0. 2) 1. 87 Compute the slope at t 2 = 0.4 and use the fact that we have the approximation y 2 = 1.87 to use in the Euler formula.
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 1.2650 y 3 =y 2 + h f(t 2,y 2 ) = 2.123 3 0.6 2.123 4 0.8 5 1.0 y1 y0 f0 h 1 ( 3 0 0. 5) ( 0. 2) 1 2. 5( 0. 2) 1. 5... y2 y1 f1 h 15. 3 2 0 2 0 5 15 ( 0. 2) 1. 87. y3 y2 f2 h 1. 87 3 2 0 4 0. 5 1. 87 ( 0. 2) 2. 123
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 1.2650 y 3 =y 2 + h f(t 2,y 2 ) = 2.123 3 0.6 2.123 4 0.8 5 1.0 y y f h 1 ( 3 0 0. 5)( 0. 2) 1 2. 5( 0. 2) 1. 5 1 0 0 2 1 1 3 2 2 y y f h 1. 5 3 2 0. 2 0. 5 1. 5 ( 0. 2) 1. 87 y y f h 1. 87 3 2 0. 4 0. 5 1. 87 ( 0. 2) 2. 123 Continue in a similar fashion.
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 1.2650 y 3 =y 2 + h f(t 2,y 2 ) = 2.123 3 0.6 2.123 0.7385 y 4 =y 3 + h f(t 3,y 3 ) = 2.2707 4 0.8 2.2707 5 1.0 y y f h 1 ( 3 0 0. 5)( 0. 2) 1 2. 5( 0. 2) 1. 5 1 0 0 2 1 1 3 2 2 4 3 3. 0.. 2 y y f h 1. 5 3 2 0. 2 0. 5 1. 5 ( 0. 2) 1. 87 y y f h 1. 87 3 2 0. 4 0. 5 1. 87 ( 0. 2) 2. 123 y y f h 2. 123 3 2 0 6 5 2 1 3 ( 0. 2) 2. 2707
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 1.2650 y 3 =y 2 + h f(t 2,y 2 ) = 2.123 3 0.6 2.123 0.7385 y 4 =y 3 + h f(t 3,y 3 ) = 2.2707 4 0.8 2.2707 5 1.0 y y f h 1 ( 3 0 0. 5)( 0. 2) 1 2. 5( 0. 2) 1. 5 1 0 0 2 1 1 3 2 2 4 3 3 5 4 4... y y f h 1. 5 3 2 0. 2 0. 5 1. 5 ( 0. 2) 1. 87 y y f h 1. 87 3 2 0. 4 0. 5 1. 87 ( 0. 2) 2. 123 y y f h 2. 123 3 2 0. 6 0. 5 2. 123 ( 0. 2) 2. 2707 y y f h 2. 2707 3 2 0 8 0 5 2 2707 ( 0. 2) 2. 32363
Example: For the initial value problem use Euler s method with h = 0.2 to approximate the solution at t = 0.2, 0.4, 0.6, 0.8, and 1.0. Index i t i y i y' I = f(t i,y i ) = f i y i+1 =y i + h f(t i,y i ) 0 0 1 2.5 y 1 =y 0 + h f(t 0,y 0 ) = 1.5 1 0.2 1.5 1.8500 y 2 =y 1 + h f(t 1,y 1 ) = 1.87 2 0.4 1.87 1.2650 y 3 =y 2 + h f(t 2,y 2 ) = 2.123 3 0.6 2.123 0.7385 y 4 =y 3 + h f(t 3,y 3 ) = 2.2707 4 0.8 2.2707 0.2646 y 5 =y 4 + h f(t 4,y 4 ) = 2.32363 5 1.0 2.32363 y y f h 1 ( 3 0 0. 5)( 0. 2) 1 2. 5( 0. 2) 1. 5 1 0 0 2 1 1 3 2 2 4 3 3 5 4 4 y y f h 1. 5 3 2 0. 2 0. 5 1. 5 ( 0. 2) 1. 87 y y f h 1. 87 3 2 0. 4 0. 5 1. 87 ( 0. 2) 2. 123 y y f h 2. 123 3 2 0. 6 0. 5 2. 123 ( 0. 2) 2. 2707 y y f h 2. 2707 3 2 0. 8 0. 5 2. 2707 ( 0. 2) 2. 32363
The exact solution to our IVP is We approximated the solution of our IVP at t = 0.2, 0.4, 0.6, 0.8, 1.0 so now let s compare our results to the exact solution at those values of t. Exact y in red Approximate y in blue 2.5 y 2.0 1.5 1.0 0.5 0.2 0.4 0.6 0.8 1.0 t
Euler Approx. 3 Direction Field for y'=3-2*t-.5*y 2.5 2 1.5 Exact 1 0.5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Note here we are looking over interval 0 t 1.
Accuracy of Euler s Method: Euler s method should not be used for real world approximations of IVPs. There are much more accurate methods available. But these other methods are used in much the same way as Euler s method. Euler s method is a recursive procedure used to obtain discrete approximations to IVPs. It generates a piecewise linear approximation by pasting together tangent line approximations. Its accuracy depends on how closely the t-values t 1, t 2, t 3, are spaced. For a very small spacing Euler s method requires a lot of steps and hence can be considered expensive. Even with small spacing certain IVPs can not be well approximated with Euler s method. Next we illustrate the behavior of Euler s method two different problems. Definition of recursive relating to, or constituting a procedure that can repeat itself indefinitely
Example: Approximate the IVP via Euler s method. The exact solution is x(t) = t + t ln(t).
Inspect the scales for the graphs. Approximate (solid) + True Soln (dotted) 18 1.4 ABS. ERROR 16 14 12 10 8 6 4 2 0 0 2 4 6 1.2 1 0.8 0.6 0.4 0.2 0 0 2 4 6
Observe the slow but steady growth in the error as t increases. Since each step introduces new error into the computed approximate solution, we might expect this type of behavior in every problem; however, the actual accumulation of error from successive steps is very problem dependent.
Euler Approx of IVP Essentially, the error introduced by each step of the time marching process moves us from one solution of the differential equation onto a different solution. (At each step we encounter a new IVP; a perturbed IVP.) If, nearby solutions separate from one another as t increases, we can expect to see a steady increase in the error. Note that a change of initial conditions had those solution curves move away from the solution curve for the original IVP. On the other hand, if nearby solutions move closer together as t increases, we could expect to observe a steady decline in the error. The next example demonstrates this situation.
Another Example: Approximate the IVP via Euler s method. True solution Here nearby solutions move closer together as t increases, so we observe a steady decline in the error.
Approximate (solid) + True Soln (dotted) 5.5 0.18 ABS. ERROR 5 0.16 4.5 0.14 4 0.12 3.5 0.1 3 0.08 2.5 0.06 2 0.04 1.5 0.02 1 0 2 4 6 0 0 2 4 6
In this case changes in the initial conditions have the nearby solutions move closer together as t increases. So we could expect to observe a steady decline in the error.
In both of these examples accuracy may be improved by choosing smaller values of the stepsize h. But this not guaranteed to happen in all cases. Here consider the IVP h = 0.25 h = 0.125 h = 0.0625 h = 0.01 dy = y 2-2t, y(-1.5) = -2.5 dt