1 Derivation of Euler's Method - Numerical Methods for Solving Differential Equations Let’s start with a general first order Initial Value Problem ππ¦ = π(π₯, π¦) π¦(π₯0 ) = π¦0 (1) ππ₯ where f(x, y) is a known function and the values in the initial condition are also known numbers. If f is continuous functions then there is a unique solution to the IVP in some interval surrounding x = x0 . So, let’s assume that everything is nice and continuous so that we know that a solution will in fact exist. We want to approximate the solution to (1) near x = x0 : 1. point (x0, y0) an exact value, known to lie on the solution curve tangent line to the ghost (unknown) solution y = f(x) at x = x0 : π¦ = π¦0 + π′(π₯0 , π¦0 )(π₯ − π₯0 ) If x1 is close enough to x0 then the point y1 on the tangent line should be fairly close to the actual value of the solution at x1, or y(x1). 2. point (x1, y1) π¦1 = π¦0 + π(π₯0 , π¦0 )(π₯1 − π₯0 ) an approximate value of f(x1) , lying on tangent line through (xo, yo). If we want other points along the path of the true solution, and yet we don't actually have the true solution, then it looks like using the tangent line as an approximation might be our best bet! After all, at least on this picture, it looks like the line stays pretty close to the curve if you don't move too far away from the initial point. We must now attempt to continue our quest for points on the solution curve (though we're starting to see the word "on" as a little optimistic—perhaps "near" would be a more realistic word here.). So in hope that we are going in the right direction we will construct pseudo-tangent line (pseudo: because it is not on the actual solution). We will substitute our new point, (x1, y1), into the formula: slope of the solution = f (x,y) to get the slope of a pseudo-tangent line to the curve at (x1,y1). We hope that our approximate point, (x1,y1), is close enough to the real solution that the pseudo-tangent line is pretty close to the unknown real tangent line. Pattern for generating new points was established 3. point (x2, y2) π¦2 = π¦1 + π(π₯1 , π¦1 )(π₯2 − π₯1 ) an approximate value, lying on tangent line through (x1, y1). π¦ = π¦1 + π(π₯1 , π¦1 )(π₯ − π₯1 ) 4. point (x3, y3) π¦3 = π¦2 + π(π₯2 , π¦2 )(π₯3 − π₯2 ) an approximate value, lying on tangent line through (x2,y2). π¦ = π¦2 + π(π₯2 , π¦2 )(π₯ − π₯2 ) π¦ = π¦0 + π(π₯0 , π¦0 )(π₯ − π₯0 ) π¦ = π¦1 + π(π₯1 , π¦1 )(π₯ − π₯1 ) π¦ = π¦2 + π(π₯2 , π¦2 )(π₯ − π₯2 ) π¦ = π¦3 + π(π₯3 , π¦3 )(π₯ − π₯3 ) Assuming that the step sizes are of uniform size: π₯π+1 − π₯π = β recursive formula for approximate points is: ππ+π = ππ + π ππ+π = ππ + ππ π ππ = π(π₯π , π¦π ) 2 Example Solve the initial value problem: y′ = x + 2y, 1, and using steps of size h = 0.25. y(0) = 0 numerically (Euler), finding a value for the solution at x = xn+1 = xn + h yn+1 = yn + h f(xn, yn) 1. point (0,0) 2. point (0.25, 0) x1 = xo + h = 0.25 y1 = yo + h f(xo, yo) = yo + h (xo + 2yo) = 0 + 0.25 (0 + 2*0) = 0 3. point (0.5, 0.0625) x2 = x1 + h = 0.5 y2 = y1 + h f (x1, y1) = y1 + h (x1 + 2y1) = 0 + 0.25 (0.25 + 2*0) = 0.0625 4. point (0.75, 0.21875) x3 = x2 + h = 0.75 y3 = y2 + h f (x2, y2) = y2 + h (x2 + 2y2) = 0.0625+0.25 (0.5+2*0.0625) = 0.21875 5. point (1, 0.515625) x4 = x3 + h = 1 y4 = y3 + h f (x3, y3) = y3 + h (x3 + 2y3)= 0.21875+0.25 (0.75+2*0.21875) = 0.515625 How accurate is this solution: NOT VERY!!! Analytically: y′ = x + 2y, ππ¦ ππ₯ ππ¦ ππ₯ y(0) = 0 linear differential equation of order 1: + π(π₯)π¦ = π(π₯) → π¦ π∫ πππ₯ = ∫ ππ∫ πππ₯ ππ₯ + πΆ − 2π¦ = π₯ π¦ π∫ −2ππ₯ = ∫ π₯π∫ −2ππ₯ ππ₯ + πΆ → π¦ π−2π₯ = ∫ π₯ π−2π₯ + πΆ → 1 1 1 π¦ π −2π₯ = π −2π₯ (−2π₯ − 1) + πΆ → π¦ = (−2π₯ − 1) + πΆπ 2π₯ & π¦(0) = 0 → πΆ = 4 4 4 π¦ = 1 2π₯ 1 π + (−2π₯ − 1) 4 4 Comparison of analytical (blue) and numerical solutions (red) with steps 0.25 and 0.02. The numerical solution gets worse and worse as we move further to the right, and becomes more accurate with the smaller steps. This method is one that truly belongs on a computer! 3 Slope Fields Purpose: To graphically express a differential equation using slope fields. Slope fields are a way to visualize a differential equation. It is simply a graph that shows the slopes at points on the coordinate plane for a differential equation. First a little review: π¦ = π₯2 + 3 πΆπππ ππππ: π¦ = π₯2 − 5 or π‘βππ: π¦′ = 2π₯ π¦′ = 2π₯ It doesn’t matter whether the constant was 3 or -5, since when we take the derivative the constant disappears. However, when we try to reverse the operation: πΊππ£ππ: π¦′ = 2π₯ ππππ π¦ π¦ = π₯2 + πΆ We don’t know what the constant is, so we put “C” in the answer to remind us that there might have been a constant. If we have some more information we can find C. πΊππ£ππ: π¦ 4 πΆ π¦ π¦′ = 2π₯ = π₯2 + πΆ = 1+πΆ =3 = π₯2 + 3 πππ π¦ = 4 π€βππ π₯ = 1 , ππππ π‘βπ πππ’ππ‘πππ πππ π¦. This is called an initial value problem. We need the initial values to find the constant. An equation containing a derivative is called a differential equation. It becomes an initial value problem when you are given the initial condition and are asked to find the original equation. Initial value problems and differential equations can be illustrated with a slope field. Slope fields are mostly used as a learning tool and are mostly done on a computer or graphing calculator, but an AP student could be asked to draw a simple one by hand. draw a segment with a slope of 0 draw a segment with a slope of 2 draw a segment with a slope of 4 4 π¦′ = 2π₯ If you know an initial condition, such as (1,-2), you can sketch the curve. By following the slope field, you get a rough picture of what the curve looks like. In this case, it is a parabola. π¦ = π₯2 + πΆ ππ π‘βπ ππππππ¦ ππ π πππ’π‘ππππ π¦ = π₯ 2 − 3 ππ π‘βπ ππππ‘πππ’πππ π ππ’ππ’π‘πππ πΈπ₯πππππ: ππ¦ ππ₯ = π₯π¦ 1 π¦(0) = 2 Only special types of differential equations can be solved analytically. In that case we don’t need neither Euler’s method nor slope field. Just for practice we chose the one that can be solved analytically: ππ¦ = π₯ ππ₯ π¦ don’t panic this is experience → ππ π¦ = π₯2 + ππ πΆ 2 π₯2 π¦ π₯2 ππ = → π¦ = πΆπ 2 πΆ 2 1 1 πππ ππππ‘πππ ππππππ‘πππ π¦(0) = 2 , πΆ = 2 ππππ‘πππ’πππ π πππ’π‘πππ: π¦ = 1 π₯2 π 2 2 The particular (specific) solution, for the initial condition (0,1), has been superimposed as the solid line on the field. Notice how the field’s lines match up with the solution’s curve. This is why slope fields are useful: they can show the shapes of the possible solutions (just follow the and connect the slope lines), as well as predict other values on the solution. Even though most graphing calculators can plot slope fields, you should know how to make them by hand. The AP test requires that you be able to identify what the slope field of a function looks like, without a graphing calculator. Making a slope field involves evaluating the differential equation at each point. 5 πΈπ₯πππππ: π·πππ€ π‘βπ π ππππ πππππ πππ ππππππππ‘πππ πππ’ππ‘πππ: ππ¦ = π₯π¦ 2 ππ₯ Solution: Start off by making some observations about what the field should look like: • On the axes, the slope is zero. • Farther from the origin, the slopes are larger. • In first and fourth quadrants, the slopes are positive. • In the second and third quadrants, the slopes are negative. Making observations like this will help you identify a slope field for a function. Next, make a table of slope values, but for simpler functions like the one given, this can usually be done in your head. Only a few slope values are shown here: Now, you are ready to graph the field. Draw a short line segment with the slope you calculated above for each of the points. The field should look something like this: Example: Match the following differential equations with their respective slope fields. ππ¦ ππ¦ ππ¦ ππ¦ π) =π₯+π¦ π) = π₯ − π¦2 π) = π₯(1 − π¦) π) = −π₯√π¦ ππ₯ ππ₯ ππ₯ ππ₯ Solution: Since graph (3) is the only graph that does not exist below the x-axis, therefore, it must go with equation (d), which has the square root. Graph (1) appears to have zero slope at y = 1, and at x = 0. The only equation to meet these criteria is equation (c). Graph (2) appears to have zero slope along a diagonal y = −x. Equation (a) meets the criterion in this case. The only one left is graph (4) and equation (b), which makes sense because the graph seems to have zero slope along y = ± √π₯. The answers are 1c, 2a, 3d, 4b. 6 Example: 1. Sketch the slope field for the differential equation: ππ¦ = 0.25(π¦ − 1)(5 − π¦) ππ₯ 2a. Describe (draw) the particular solution with the initial condition y(0)=6 2b. Describe (draw) the particular solution with the initial condition y(0)=5 2c. Describe (draw) the particular solution with the initial condition y(0)=3 2d. Describe (draw) the particular solution with the initial condition y(0)=1 2e. Describe (draw) the particular solution with the initial condition y(0)=0 1. 2a,c. 2b,d. 2e. 7 SOLUTIONS: 1 2a. starting at the point (0, 6) will go down toward the line y = 5. 2b. The trajectory starting at the point (0, 5)will stay along the line y = 5 2d. The trajectory starting at the point (0, 1) will stay along the line y = 1 2c. The trajectory starting at at the point (0, 3) will go up toward the line y = 5 2e. The trajectory starting at the point (0, 0) will go down toward – ∞ 8 PROBLEMS: 1. Use Euler’s method with the step size 0.1 to approximate y(1) where y(x) is the solution of the initial-value problem y’= x+y, y(0)=1. 2. Use Euler’s method with the step size 0.2 to approximate y(2) where y(x) is the solution of the initial-value problem y’= y- e-x , y(0) = 1. 3. Use Euler’s method with the step size 0.1 to approximate y(1) where y(x) is the solution of the initial-value problem y’= sin(x+y), y(0) = 0. 4. Use Euler’s method with the step size 0.5 to approximate the size of fish population at time t = 5 where time t is measured in weeks if there are 4 fish initially and the size of the population is changing according to the equation y’ = - 0.045y(y-20). 9 5. For the IVP (Initial value problem): π¦′ + 2π¦ = 2 − π −4π‘ π¦(0) = 1 use Euler’s method with a step size of h = 0.1 to find approximate values of the solution at t = 0.1, 0.2, 0.3, 0.4, and 0.5. Compare them to the exact values of the solution as these points using: πππππππ‘ πππππ = |ππ₯πππ‘ − ππππππ₯ππππ‘π| × 100% ππ₯πππ‘ Solution of this linear differential equation is 1 1 π¦(π‘) = 1 + π −4π‘ − π −2π‘ 2 2 what could be checked by substitution into diff. eq. Conclusion about errors? 10 Slope Fields (Nancy Stephenson Clements High School Sugar Land, Texas) 6. – 11. Draw a slope field for each of the following differential equations. Each tick mark is one unit. 6. ππ¦ = π₯+1 ππ₯ 9. ππ¦ = 2π₯ ππ₯ 7. 10. ππ¦ = 2π¦ ππ₯ ππ¦ = π¦ −1 ππ₯ 8. ππ¦ =π₯+π¦ ππ₯ 11. ππ¦ π¦ =− ππ₯ π₯ 11 Match the slope fields with their differential equations. 12. ππ¦ = π ππ π₯ ππ₯ 13. ππ¦ =π₯−π¦ ππ₯ 14. ππ¦ =2−π¦ ππ₯ 15. ππ¦ =π₯ ππ₯ Match the slope fields with their differential equations. ππ¦ 16. ππ₯ = 0.5π₯ − 1 ππ¦ 17. ππ₯ = 0.5π¦ ππ¦ π₯ 18. ππ₯ == − π¦ ππ¦ 19. ππ₯ = π₯ + π¦ 12 20. The slope field from a certain differential equation is shown above. Which of the following could be a specific solution to that differential equation? (π΄) π¦ = π₯ 2 (π΅) π¦ = π π₯ (πΆ) π¦ = π −π₯ (π·) π¦ = πππ π₯ (πΈ) π¦ = ππ π₯ 21. The slope field for a certain differential equation is shown below. Which of the following could be a specific solution to that differential equation? (π΄) π¦ = π ππ π₯ (π΅) π¦ = πππ π₯ (πΆ) π¦ = π₯ 2 1 (π·) π¦ = π₯ 3 6 (πΈ) π¦ = ππ π₯ 13 ππ¦ π₯π¦ 22. Consider the differential equation given by ππ₯ = 2 (A) On the axes provided, sketch a slope field for the given differential equation. (B) Let f be the function that satisfies the given differential equation. Write an equation for the tangent line to the curve y = f (x) through the point (1, 1). Then use your tangent line equation to estimate the value of f (1.2). (C) Find the particular solution y = f (x) to the differential equation with the initial condition f (1) =1. Use your solution to find f (1.2). (D) Compare your estimate of f (1.2) found in part (b) to the actual value of f (1.2) found in part (E) Was your estimate from part (b) an underestimate or an overestimate? Use your slope field to explain why. 14 ππ¦ π₯ 23. Consider the differential equation given by ππ₯ = π¦ (A) On the axes provided, sketch a slope field for the given differential equation. (B) Sketch a solution curve that passes through the point (0, 1) on your slope field. (C) Find the particular solution y = f (x) to the differential equation with the initial condition f (0) =1. (D) Sketch a solution curve that passes through the point (0, −1) on your slope field. (E) Find the particular solution y = f (x) to the differential equation with the initial condition f (0) = −1. 15 Solutions: 1. y(1)=3.187 2. y(2) = 3.014 3. y(1) = 0.501 4. y(5) = 19.42. Thus, there is approximately 19 fish after 5 weeks. 5. the error is clearly getting much worse as t increases. Time, tn t0 = 0 t1 = 0.1 t2 = 0.2 t3 = 0.3 t4 = 0.4 t5 = 0.5 Approximation y0 =1 y1 =0.9 y2 =0.852967995 y3 =0.837441500 y4 =0.839833779 y5 =0.851677371 Exact y(0) = 1 y(0.1) = 0.925794646 y(0.2) = 0.889504459 y(0.3) = 0.876191288 y(0.4) = 0.876283777 y(0.5) = 0.883727921 Error 0% 2.79 % 4.11 % 4.42 % 4.16 % 3.63 % 16 17 18 19 20