Homework Solutions Igor Yanovsky Math 5B TA Section 5.3, Problem b: Use Taylor s method of order two to approximate the solution for the following initial-value problem: y = + t y, t 3, y =, with h = 0.5. problem Let us first derive the Taylor s method or order two for general initial value y = ft, y, a t b, ya = α. Expand the solution yt in terms of its second Taylor polynomial about t i and evaluate at t i+, we obtain yt i+ = yt i + hy t i + h y t i + h3 6 y ξ i, 3 for some ξ i t i, t i+. Since we have y t = ft, yt, differentiating y t twice gives y t = f t, yt, y t = f t, yt. Plugging these into 3 gives yt i+ = yt i + hft i, yt i + h f t i, yt i + h3 6 f ξ i, yξ i. 4 When h is small, the last term in 4 is small, and thus, we can ignore it. The Taylor s method of order two for general initial value problem is therefore w i+ = w i + hft i, w i + h f t i, w i. 5 For the initial value problem, we have ft, yt = + t y, f t, yt = d dt + t y = t y y = t y + t y = t y 3. Equation 5, with t i = + 0.5i, becomes w i+ = w i + h + t i w i h t i w i 3 = w i + 0.5 + + 0.5i w i 0.5 + 0.5i w i 3.
Hence, with w 0 =, we have w = w 0 + 0.5 + w 0 0.5 w 0 3 = + 0.5 + 0.5 =.75, w = w + 0.5 + + 0.5 w 0.5 + 0.5 w 3 =.75 + 0.5 + + 0.5.75 0.5 + 0.5.75 3 =.4578. Section 5.3, Problem c: Use Taylor s method of order two to approximate the solution for the following initial-value problem: y = + y t, t, y =, 6 with h = 0.5. The Taylor s method of order two for general initial value problem is given by equation 5. For the initial value problem 6, we have ft, yt = + y t, f t, yt = d + y = y t y dt t t Equation 5, with t i = + 0.5i, becomes w i+ = w i + h + w i t i = w i + 0.5 + Hence, with w 0 =, we have + h t i w i + 0.5i = + y t t y t = t. + 0.035 + 0.5i w = w 0 + 0.5 + w 0 + 0.035 =.785, w = w + 0.5 + w + 0.035 = 3.65,.5.5 and, similarly, calculate w 3 and w 4..
Problem : Assume that yt = 4 cos t 7t 4 3 is the solution to some initial value problem on t 3. a Calculate the local truncation error when Euler s method is applied to this problem. Derive an upper bound for the local truncation error at t = 3 if the stepsize is h = 0.00. b For the same function yt, and also for h = 0.00, find an upper bound for the global error for Euler s method at t = 3, if we assume that the Lipschitz constant is L =. You would likely get a bigger number than the local truncation error. a Since yt = 4 cos t 7t 4 3, we have y t = 4 sin t t 4 and y t = 4 cos t 4t 4. Thus, ft, y = y t = 4 sin t t 4. Euler s method w i+ = w i + hft i, w i has local truncation error τ i+ h = h y i+ y i + hft i, y i = 7 = y i+ y i h For this problem, we have τ i+ h = y i+ y i h ft i, y i. + 4 sin t i + t i 4. Local truncation error measures the accuracy of the method at a specific step, assuming that the method was exact at the previous step. It is important to note that this error depends on the differential equation, the step size, and the particular step in the approximation. We know the differential equation, i.e., we know ft, y. Hence, the local truncation error is a function of the step size h and the particular step i. The local truncation error for Euler s method is: τ i+ h = h y ξ i, for some ξ i in t i, ti +. The upper bound for the local truncation error is τ i+ h h M. At t = 3, we have y 3 = 4 cos 3 43 4 = 45.96. Hence, for h = 0.00, at t = 3 we have τ i+ h = 0.00 0.00 45.96 = 0.03. 3
b The formula for calculating the global error is located on page 37 of the textbook: yt i w i τh L elt i a, where τ i h satisfies τ i h τh. Since y t = 4 cos t 4t 4, we have which gives y t 4 cos t 4t 4 50.4 = M, τh h M = 0.00 Thus, the global error is yt i w i 0.5 50.4 = 0.5. e 3+ = 379. 4
Problem 3: Use the midpoint method to approximate the solution to the initial value problem y = + t y, t 3, y =, 8 with stepsize h = 0.5. The exact solution is yt = t +. Compare the approximate t and exact solutions. The Runge-Kutta Midpoint method for the solution of the initial value problem y = ft, y, a t b, ya = α, can be written as w i+ = w i + hf t i + h, w i + h ft i, w i, i = 0,,.... 9 0 For the initial value problem in 8, t i = + ih, i.e. t 0 =.0, t =.5, t = 3.0, and we need to take only two steps, calculating w at time t, and w at time t. We have: w 0 =, w = w 0 + hf t 0 + h, w 0 + h ft 0, w 0 = + 0.5f + 0.5, + 0.5 + 3 = + 0.5f.5,.5 4 = + 0.5 +.5.5 =.785, 5 w = w + hf t + h, w + h ft, w 6 =.785 + 0.5f.5 + 0.5,.785 + 0.5f.5,.785 7 =.785 + 0.5f.75,.785 + 0.5 +.5.785 8 =.785 + 0.5f.75,.6040 9 =.785 + 0.5 +.75.6040 0 =.455064. The exact solution gives the following values: yt =.5 =.8333 and yt = 3 =.5. Note that these results are more accurate than the results obtained with Euler s method in Homework. 5
Problem 4: Consider the initial value problem y = + y t, t, y =. The exact solution to this problem is yt = t log t + t. a If Euler s method is used to solve this problem and an accuracy of 0 4 is desired for the final value y, what stepsize h should be used approximately? b Write a code for Euler s method and use it to solve this problem using the h in part a. Plot both the numerical and exact solutions at all intermediate mesh points. c Repeat part b with midpoint method. d Repeat part c with step with stepsize h. Then use the numerical results from c and d to estimate the order p of the midpoint method. Hint: Oh p is the global error for the method when a stepsize h is used. a We will use the following formula to obtain the stepsize h: yt i w i hm [ e Lt i a ]. 3 L We first find M and L. We have y t = log t+3, and y t =. The bound M is obtained t from: y t = = M, t. Also, since ft, y = + y, we have t t f y = t = = L, t. 4 Plugging these into 3, we get 0 4 = h [ e ], h =.64 0 4. b Running the code gives: N = 859, h =.640088e 004, t =.00, w = 5.3863664e + 000, y = 5.3869436e + 000, error = 5.89875389e 005. As expected, with stepsize h =.64 0 4 from part a, we obtained the desired accuracy of 0 4. Check the plots of the exact solution and the solution obtained using Euler s method. The plots of the functions are overlaid due to sufficient accuracy. 6
c The Runge-Kutta Midpoint method for the solution of the initial value problem is y = ft, y, a t b, ya = α, w i+ = w i + hf t i + h, w i + h ft i, w i, i = 0,,.... 5 6 Running the Runge-Kutta Midpoint method program gives: N = 859, h =.640088e 004, t =.00, w = 5.386943603e + 000, y = 5.3869436e + 000, error = 8.505300e 00. Thus, RK Midpoint rule gives considerably more accurate results than Euler s method. d Running the Midpoint program gives the following results: N = 78, h = 5.80044e 005, t =.00, w = 5.386943609e+000, y = 5.3869436e+ 000, error =.065689844e 00. Order of convergence: p = log wh y exact 0 w h/ y exact log 0.0 = log 0 8.505300e 00.065689844e 00.04. log 0.0 We obtain the rd, or quadratic, order of convergence, for the second order Runge-Kutta Midpoint method, which is expected. 7