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,½), 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 – ∞