EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor corrector Methods EE3561_Unit 8 Al-Dhaifallah1435 1 Lessons in Topic 8 Lesson 1: Introduction to ODE Lesson 2: Taylor series methods Lesson 3: Midpoint and Heun’s method Lessons 4-5: Runge-Kutta methods Lesson 6: Solving systems of ODE EE3561_Unit 8 Al-Dhaifallah1435 2 Learning Objectives of Lesson 3 To be able to solve first order differential equation using Midpoint Method To be able to solve first order differential equation using Heun’s Predictor Corrector method EE3561_Unit 8 Al-Dhaifallah1435 3 Outlines of Lesson 3 Lesson 3: Midpoint and Heun’s Predictor-corrector methods Review Euler Method • Heun’s Method • Midpoint method • EE3561_Unit 8 Al-Dhaifallah1435 4 Euler Method Problem y ( x) f ( x, y ) Euler Method y ( x0 ) y0 yi 1 yi h f ( xi , yi ) y0 y ( x0 ) for i 1,2,... 2 Local Truncation Error O(h ) Global Truncation Error O(h ) EE3561_Unit 8 Al-Dhaifallah1435 5 Introduction Problem to be solved is a first order ODE y ( x) f ( x, y ), y ( x0 ) y0 We have seen Taylor series method • Euler method is simple but not accurate • Higher order Taylor series methods are accurate but require calculating higher order derivatives analytically yi 1 yi h EE3561_Unit 8 Al-Dhaifallah1435 6 Introduction Problem to be solved is a first order ODE y ( x) f ( x, y ), y ( x0 ) y0 The methods proposed in this lesson have the general form yi 1 yi h For the case of Euler f ( xi , yi ) Different forms of will be used for the midpoint and Heun’s methods EE3561_Unit 8 Al-Dhaifallah1435 7 Midpoint Method Problem y ( x ) f ( x, y ) y ( x0 ) y0 Midpoint M ethod y0 y ( x0 ) y i 1 2 h yi f ( xi , yi ) 2 yi 1 yi h f ( x 1 i 2 Local Truncation Error O(h 3 ) Global Truncation Error O(h 2 ) EE3561_Unit 8 Al-Dhaifallah1435 ,y 1 i 2 ) 8 Motivation The midpoint can be summarized as Euler method is used to estimate the solution at the midpoint. The value of the rate function f(x,y) at the mid point is calculated This value is used to estimate yi+1. Local Truncation error of order O(h3) Comparable to Second order Taylor series method EE3561_Unit 8 Al-Dhaifallah1435 9 Midpoint Method ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 10 Midpoint Method slope f ( xi , yi ) ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 11 Midpoint Method slope f ( xi , yi ) (x 1 i 2 ,y 1 i 2 ) ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 12 Midpoint Method slope f ( x (x 1 i 2 ,y 1 i 2 1 2 i ) ,y i 1 2 ) ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 13 Midpoint Method slope f ( x (x 1 i 2 ,y 1 i 2 1 i 2 ) ,y 1 i 2 ) ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 14 Midpoint Method slope f ( x (x 1 i 2 ,y 1 i 2 1 i 2 ) ,y 1 i 2 ) ( xi , yi ) x0 y 1 i 2 h yi f ( xi , yi ) , 2 EE3561_Unit 8 x 1 i 2 xi 1 yi 1 yi h f ( x 1 i 2 Al-Dhaifallah1435 ,y 1 i 2 ) 15 Example 1 Use the Midpoint Method to solve the ODE y ( x) 1 x 2 y y (0) 1 Use h 0.1. Determine y(0.1) and y(0.2) EE3561_Unit 8 Al-Dhaifallah1435 16 Example 1 Problem : f ( x, y ) 1 y x 2 , y0 y ( x0 ) 1, h 0.1 Step 1 : y 0 1 2 h y0 f ( x0 , y0 ) 1 0.05(1 0 1) 1.1 2 y1 y0 h f ( x 1 0 2 ,y 1 0 2 ) 1 0.1(1 0.0025 1.1) 1.2103 Step 2 : y 1 1 2 h y1 f ( x1 , y1 ) 1.2103 .05(1 0.01 1.2103) 1.3213 2 y2 y1 h f ( x 1 1 2 EE3561_Unit 8 ,y 1 1 2 ) 1.2103 0.1( 2.3438) 1.4446 Al-Dhaifallah1435 17 Summary The midpoint can be summarized as Euler method is used to estimate the solution at the midpoint. The value of the rate function f(x,y) at the mid point is calculated This value is used to estimate yi+1. Local Truncation error of order O(h3) Comparable to Second order Taylor series method EE3561_Unit 8 Al-Dhaifallah1435 18 Heun’s Predictor Corrector EE3561_Unit 8 Al-Dhaifallah1435 19 Heun’s Predictor Corrector Method Heun ' s Method Problem y ( x ) f ( x, y ) y ( x0 ) y0 y0 y ( x0 ) Predictor : yi01 yi h f ( xi , yi ) Corrector : y k 1 i 1 Local Truncation Error O(h 3 ) Global Truncation Error O(h 2 ) EE3561_Unit 8 h yi f ( xi , yi ) f ( xi 1 , yik1 ) 2 Al-Dhaifallah1435 20 Heun’s Predictor Corrector (Prediction) ( xi 1 , yi01 ) ( xi , yi ) xi xi 1 0 i 1 Preidectio n y EE3561_Unit 8 yi h f ( xi , yi ) Al-Dhaifallah1435 21 Heun’s Predictor Corrector (Prediction) ( xi 1 , yi01 ) slope f ( xi 1 , yi01 ) ( xi , yi ) xi xi 1 0 i 1 Preidectio n y EE3561_Unit 8 yi h f ( xi , yi ) Al-Dhaifallah1435 22 Heun’s Predictor Corrector (Prediction) f ( xi , yi ) f ( xi 1 , yi01 ) slope 2 ( xi 1 , yi11 ) ( xi , yi ) xi xi 1 0 i 1 Preidectio n y EE3561_Unit 8 ( xi 1 , yi01 ) yi h f ( xi , yi ) Al-Dhaifallah1435 23 Heun’s Predictor Corrector ( xi 1 , yi01 ) ( xi 1 , yi11 ) ( xi , yi ) x0 yi 1 yi h f ( xi , yi ) , EE3561_Unit 8 slope f ( xi 1 , yi 1 ) xi 1 y 1 i 1 h yi f ( xi , yi ) f ( xi 1 , yi01 ) 2 Al-Dhaifallah1435 24 Heun’s Predictor Corrector ( xi 1 , yi01 ) ( xi 1 , yi11 ) ( xi , yi ) x0 yi 1 yi h f ( xi , yi ) , EE3561_Unit 8 slope f ( xi 1 , yi 1 ) xi 1 y 1 i 1 h yi f ( xi , yi ) f ( xi 1 , yi01 ) 2 Al-Dhaifallah1435 25 Example 2 Use the Heun' s Method to solve the ODE y ( x) 1 x y 2 y ( 0) 1 Use h 0.1. One correction only Determine y(0.1) and y(0.2) EE3561_Unit 8 Al-Dhaifallah1435 26 Example 2 Problem : f ( x, y ) 1 y x 2 , y0 y ( x0 ) 1, h 0.1 Step 1 : Predictor : y10 y0 h f ( x0 , y0 ) 1 0.1( 2) 1.2 h Corrector : y y0 f ( x0 , y0 ) f ( x1 , y10 ) 1.2105 2 Step 2 : 1 1 Predictor : y20 y1 h f ( x1 , y1 ) 1.4326 h Corrector : y y1 f ( x1 , y1 ) f ( x2 , y20 ) 1.4452 2 1 2 EE3561_Unit 8 Al-Dhaifallah1435 27 Summary Euler, Midpoint and Heun’s methods are similar in the following sense: yi 1 yi h slope Different methods use different estimates of the slope Both Midpoint and Heun’s methods are comparable in accuracy to second order Taylor series method. EE3561_Unit 8 Al-Dhaifallah1435 28 Comparison Method Local truncation error yi 1 yi h f ( xi , yi ) Euler Method Global truncation error O(h 2 ) O ( h) O(h 3 ) O(h 2 ) O(h 3 ) O(h 2 ) Heun' s Method Predictor : yi01 yi h f ( xi , yi ) h Corrector : y yi f ( xi , yi ) f ( xi 1 , yik1 ) 2 h Midpoint y 1 yi f ( xi , yi ) i 2 2 k 1 i 1 yi 1 yi h f ( x i EE3561_Unit 8 1 2 ,y i Al-Dhaifallah1435 1 2 ) 29 More in this Unit Lessons 4-5: Runge-Kutta Methods Lesson 6: Systems of High order ODE Lesson 7: Multi-step methods Lessons 8-9: Boundary Value Problems EE3561_Unit 8 Al-Dhaifallah1435 30 EE 3561 : Computational Methods Topic 8 Solution of Ordinary Differential Equations Lesson 4: Runge-Kutta Methods EE3561_Unit 8 Al-Dhaifallah1435 31 Lessons in Topic 8 Lesson 1: Introduction to ODE Lesson 2: Taylor series methods Lesson 3: Midpoint and Heun’s method Lessons 4-5: Runge-Kutta methods Lesson 6: Solving systems of ODE EE3561_Unit 8 Al-Dhaifallah1435 32 Learning Objectives of Lesson 4 To understand the motivation for using Runge Kutta method and basic idea used in deriving them. To Familiarize with Taylor series for functions of two variables Use Runge Kutta of order 2 to solve ODE EE3561_Unit 8 Al-Dhaifallah1435 33 Motivation We seek accurate methods to solve ODE that does not require calculating high order derivatives. The approach is to suggest a formula involving unknown coefficients then determine these coefficients to match as many terms of the Taylor series expansion EE3561_Unit 8 Al-Dhaifallah1435 34 Runge-Kutta Method Second Order Runge Kutta K1 h f (t , x) K 2 h f (t h, x K1 ) x(t h) x(t ) w1 K1 w2 K 2 Problem : Find , , w1 , w2 such that x(t h) is as accurate as possible. EE3561_Unit 8 Al-Dhaifallah1435 35 Lecture Taylor Series in Two Variables The Taylor Series discussed in Chapter 4 is extended to the 2-independent variable case. This is used to prove RK formula EE3561_Unit 8 Al-Dhaifallah1435 36 Taylor Series in One Variable The Taylor Series expansion of f(x) n 1 i h (i ) f ( x h) f ( x ) i 0 i! Approximation n h (n) f (x) n! Error where x is between x and x h EE3561_Unit 8 Al-Dhaifallah1435 37 Taylor Series in One Variable another look Define i d i d f ( x) (i ) i f ( x) h h f ( x) h i dx dx The Taylor Series expansion of f(x) i n 1 i n 1 d 1 d f ( x h) h f ( x ) h f ( x ) n! dx i 0 i! dx x is between x and x h EE3561_Unit 8 Al-Dhaifallah1435 38 Definitions Define i f i h f ( x , y ) h x i x i 0 h f ( x, y ) f ( x, y ) k y x 1 f ( x, y ) f ( x, y ) h f ( x, y ) h k k y x y x 2 2 2 f ( x, y ) 2 f ( x, y ) f ( x, y ) 2 2 h f ( x, y ) h k 2h k k 2 y x xy y 2 x EE3561_Unit 8 Al-Dhaifallah1435 39 Taylor Series Expansion f(x, y) ( x 1)( x y 2) 2 Parial derivative s evaluated at (0,0) 0 h k f ( x, y ) 4 y x ( 0. 0 ) 1 h k f ( x, y ) h fx k f y y x ( 0 .0 ) EE3561_Unit 8 Al-Dhaifallah1435 ( 0,0) 40 Taylor Series in Two Variables The Taylor Series expansion of f(x, y) i n 1 1 f ( x h, y k ) h k f ( x, y ) h k f ( x , y ) y n! x y i 0 i! x n 1 approximation error ( x , y ) is on the line joining between ( x, y ) and ( x h, y k ) y+k y x EE3561_Unit 8 x+h Al-Dhaifallah1435 41 Runge-Kutta Method Second Order Runge Kutta K1 h f (t , x) K 2 h f (t h, x K1 ) x(t h) x(t ) w1 K1 w2 K 2 Problem : Find , , w1 , w2 such that x(t h) is as accurate as possible. EE3561_Unit 8 Al-Dhaifallah1435 42 Runge-Kutta Method Problem : Find , , w1 , w2 to match as many terms as possible. h2 h3 x(t h) x(t ) hx' (t ) x' ' (t ) x' ' ' (t ) ... 2 6 x(t h) x(t ) w1h f (t , x) w2 f (t h, x h f (t , x)) 1 f (t h, x h f ) f h f t h f x h h f (t , x ) 2 t x 2 x(t h) x(t ) w1 w2 h f (t , x) w2 h 2 f t w2 h 2 f f t O(h 3 ) EE3561_Unit 8 Al-Dhaifallah1435 43 Runge-Kutta Method x(t h) x(t ) h2 x' ' (t ) 2 hx' (t ) h3 x' ' ' (t ) ... 6 x(t h) x(t ) w1 w2 h f (t , x) w2 h 2 f t w2 h 2 f f t w1 w2 1, w2 0.5, O(h3 ) w2 0.5 One possible solution w1 0.5, EE3561_Unit 8 w2 0.5, 1, Al-Dhaifallah1435 1 44 Runge-Kutta Method Second Order Runge Kutta K1 h f (t , x) K 2 h f (t h, x K1 ) 1 x(t h) x(t ) K1 K 2 2 EE3561_Unit 8 Al-Dhaifallah1435 45 Runge-Kutta Method Alternative Formula Second Order Runge Kutta F1 f (t , x) F2 f (t h, x hF1 ) h x(t h) x(t ) F1 F2 2 EE3561_Unit 8 Al-Dhaifallah1435 46 Runge-Kutta Method Alternative Formula Second Order Runge Kutta Alternativ e Form K1 h f (t , x) F1 f (t , x) K 2 h f (t h, x K1 ) F2 f (t h, x hF1 ) 1 x(t h) x(t ) K1 K 2 2 h x(t h) x(t ) F1 F2 2 EE3561_Unit 8 Al-Dhaifallah1435 47 Runge-Kutta Method Alternative Formulas w1 w2 1, w2 0.5, w2 0.5 another solution Pick any non - zero number , 1 w1 1 , 2 1 w2 2 Second Order Runge Kutta Formulas (select 0) K1 h f (t , x) K 2 h f (t h, x K1 ) 1 1 x(t h) x(t ) 1 F2 F1 2 2 EE3561_Unit 8 Al-Dhaifallah1435 48 Runge-Kutta Method Fourth Order Runge Kutta K1 h f (t , x) 1 1 K 2 h f (t h, x K1 ) 2 2 1 1 K 3 h f (t h, x K 2 ) 2 2 K 4 h f (t h, x K 3 ) 1 x(t h) x(t ) K1 2 K 2 2 K 3 K 4 6 EE3561_Unit 8 Al-Dhaifallah1435 49 Second order Runge-Kutta Method Example Solve the following system to find x(1.02) using RK2 x(t ) 1 x 2 (t ) t 3 , EE3561_Unit 8 x(1) 4, h 0.01 Al-Dhaifallah1435 50 Second order Runge-Kutta Method Example Solve the following system to find x(1.02) using RK2 x (t ) 1 x 2 (t ) t 3 , x (1) 4, h 0.01 STEP 1 : K1 h f (t , x ) 0.01(1 x 2 t 3 ) 0.18 K 2 h f (t h, x K1 ) 0.01(1 ( x 0.18) 2 (t .01)3 ) 0.1662 1 1 x (1 0.01) x (1) K1 K 2 4 (0.18 0.1662) 3.8269 2 2 EE3561_Unit 8 Al-Dhaifallah1435 51 Second order Runge-Kutta Method Example STEP 2 K1 h f (t , x) 0.01(1 x 2 t 3 ) 0.1666 K 2 h f (t h, x K1 ) 0.01(1 ( x 0.1666) 2 (t .01)3 ) 0.1545 1 x(1.01 0.01) x(1.01) K1 K 2 2 1 3.8254 (0.1666 0.1545) 3.6648 2 EE3561_Unit 8 Al-Dhaifallah1435 52 x (t ) 1 x (t ) t , x(1) 4, 2 3 Solution for t [1,2] Using RK2 EE3561_Unit 8 Al-Dhaifallah1435 53 Summary Runge Kutta methods generate accurate solution without the need to calculate high order derivatives. Second order RK have local truncation error of order O(h3) Fourth order RK have local truncation error of order O(h5) N function evaluations are needed in N th order RK method. EE3561_Unit 8 Al-Dhaifallah1435 54 More in this unit Lesson 5: Applications of Runge-Kutta Methods To solve first order differential equations. Lessons 6: Solving Systems of high order ODE. EE3561_Unit 8 Al-Dhaifallah1435 55
© Copyright 2026 Paperzz