ENGR 232 Dynamic Engineering Systems Lecture 1.2 - Appendix Introduction to Numerical Solution s with Differential Equations Dr. Michael Ryan Runge-Kutta Methods • Euler uses information from the current pair (tn, yn) to determine value at the next pair (tn+1, yn+1) • Runge-Kutta (2nd and 4th order methods) use a look ahead to get the slopes at strategically chosen nearby points which are weighted to maximize the accuracy of the approximation. ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 201/06/2016 Second-order Runge-Kutta (aka midpoint method) • Use slope at (tn, yn) to look a half-step ahead to the point • Compute slope at this midpoint and use this slope to move from (tn, yn) to (tn+1, yn+1) • The algorithm follows ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 3 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏+ 𝒉 𝟐 𝒇(𝒕𝒏, 𝒚𝒏) 01/06/2016 Second-order Runge-Kutta (aka midpoint method) Given the IVP 𝑦′ = 𝑓 𝑡, 𝑦 𝑦 𝑡0 = 𝑦0 And a step size of h To go from 𝑡𝑛,𝑦𝑛 𝑡𝑜 𝑡𝑛+1, 𝑦𝑛+1 𝑢𝑠𝑒: where ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 4 𝒌𝒏𝟐 = 𝒇 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏 + 𝒉 𝟐 𝒌𝒏𝟏 𝒌𝒏𝟏 = 𝒇 𝒕𝒏, 𝒚𝒏 𝒕𝒏+𝟏 = 𝒕𝒏 + 𝒉 𝒚𝒏+𝟏 = 𝒚𝒏 + 𝒉𝒌𝒏𝟐 01/06/2016 Numerical Example Consider Euler h = 0.5 step from t = 0.0 to 0.5 ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 5 t y Euler dydt y analytic error 0 1 -1 1.000 0.000 0.5 0.5 0 0.713 0.213 𝒌𝒏𝟏 = 𝒇 𝒕𝒏, 𝒚𝒏 = 𝐟 𝟎, 𝟏 = (𝐭 − 𝐲) = −𝟏 𝒕𝒏+𝟏 = 𝒕𝒏 + 𝒉 = 𝟎. 𝟓 𝒚𝒏+𝟏 = 𝒚𝒏 + 𝒉𝒌𝒏𝟐 = 𝟏 − 𝟎. 𝟐𝟓 = 𝟎. 𝟕𝟓 𝒌𝒏𝟐 = 𝒇 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏 + 𝒉 𝟐 𝒌𝒏𝟏 = 𝒇 𝟎. 𝟐𝟓,𝟎. 𝟕𝟓 = −𝟎.𝟓 Using Runge-Kutta at t = 0.5, y = 0.75 Compare to Euler; RK error is -0.037 01/06/2016 Forth-order Runge-Kutta Given the IVP 𝑦′ = 𝑓 𝑡, 𝑦 𝑦 𝑡0 = 𝑦0 And a step size of h; to go from 𝑡𝑛, 𝑦𝑛 𝑡𝑜 𝑡𝑛+1, 𝑦𝑛+1 : First computing ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 6 𝒌𝒏𝟏 = 𝒇 𝒕𝒏, 𝒚𝒏 𝒕𝒏+𝟏 = 𝒕𝒏 + 𝒉 𝒚𝒏+𝟏 = 𝒚𝒏 + 𝒉 𝟔 𝒌𝒏𝟏 + 𝟐𝒌𝒏𝟐 + 𝟐𝒌𝒏𝟑 + 𝒌𝒏𝟒 𝒌𝒏𝟐 = 𝒇 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏 + 𝒉 𝟐 𝒌𝒏𝟏 𝒌𝒏𝟑 = 𝒇 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏 + 𝒉 𝟐 𝒌𝒏𝟐 𝒌𝒏𝟒 = 𝒇 𝒕𝒏 + 𝒉 𝟐 , 𝒚𝒏 + 𝒉𝒌𝒏𝟑 01/06/2016 Error Comparison Method One step result Actual Error Exact y(1) = 0.1487… Euler y(1) = 0 0.1487… 2nd Runge-Kutta y(1) = 0.125 0.0237… 4th Runge-Kutta y(1) = 0.15 0.0013… ENGR 232 Winter 16 Lecture 1.2 – Dr. M. Ryan 7 ...