Sec:5.4 RUNGE-KUTTA METHODS.

Slides:



Advertisements
Similar presentations
Lecture on Numerical Analysis Dr.-Ing. Michael Dumbser
Advertisements

Ordinary Differential Equations
Chapter 6 Differential Equations
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L8&9 KFUPM.
HAMPIRAN NUMERIK SOLUSI PERSAMAAN DIFERENSIAL (lanjutan) Pertemuan 12 Matakuliah: METODE NUMERIK I Tahun: 2008.
Ordinary Differential Equations
PART 7 Ordinary Differential Equations ODEs
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Ordinary Differential Equations Equations which are.
Initial-Value Problems
Numerical Solutions of Ordinary Differential Equations
Ordinary Differential Equations (ODEs)
Differential Equations and Boundary Value Problems
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
ME451 Kinematics and Dynamics of Machine Systems Dynamics of Planar Systems Tuesday, November 30, 2010 Numerical Solution of IVPs [not in the book] © Dan.
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential.
PART 7 Ordinary Differential Equations ODEs
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
ME451 Kinematics and Dynamics of Machine Systems Dynamics of Planar Systems November 29, 2011 Elements of the Numerical Solution of the Dynamics Problem.
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
ME451 Kinematics and Dynamics of Machine Systems Numerical Solution of DAE IVP Newmark Method November 1, 2013 Radu Serban University of Wisconsin-Madison.
Computational Method in Chemical Engineering (TKK-2109)
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Integration of 3-body encounter. Figure taken from
Scientific Computing Multi-Step and Predictor-Corrector Methods.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 7 - Chapter 25.
The simple pendulum (Formulation as a differential-algebraic equation) Consider a small mass m attached to a light inelastic string of length l, with the.
Please remember: When you me, do it to Please type “numerical-15” at the beginning of the subject line Do not reply to my gmail,
ME451 Kinematics and Dynamics of Machine Systems Numerical Integration. Stiffness: Implicit Methods. October 30, 2013 Radu Serban University of Wisconsin-Madison.
Dr. Mujahed AlDhaifallah ( Term 342)
ME451 Kinematics and Dynamics of Machine Systems Dealing with Differential Equations ~ A Numerical Approach ~ March 12, 2009 © Dan Negrut, 2009 ME451,
Today’s class Ordinary Differential Equations Runge-Kutta Methods
Sec 21: Generalizations of the Euler Method Consider a differential equation n = 10 estimate x = 0.5 n = 10 estimate x =50 Initial Value Problem Euler.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
1/14  5.2 Euler’s Method Compute the approximations of y(t) at a set of ( usually equally-spaced ) mesh points a = t 0 < t 1
Sec 232: The coefficient tableau 2ed order RK method Expand all f around (x,y) using Taylor expansion in 2d and then choose constants such that the equation.
This chapter is concerned with the problem in the form Chapter 6 focuses on how to find the numerical solutions of the given initial-value problems. Main.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Keywords (ordinary/partial) differencial equation ( 常 / 偏 ) 微分方程 difference equation 差分方程 initial-value problem 初值问题 convex 凸的 concave 凹的 perturbed problem.
INTEGRATOR CLASSIFICATION & CHARACTERISTICS
Ordinary Differential Equations
Engineering Problem Solution
Part 7 - Chapter 25.
Numerical Methods by Dr. Laila Fouad.
Ordinary Differential Equations
525602:Advanced Numerical Methods for ME
Class Notes 18: Numerical Methods (1/2)
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
Class Notes 19: Numerical Methods (2/2)
Chapter 27.
Sec:25.3 RUNGE-KUTTA METHODS.
Chapter 26.
Part 7 - Chapter 25.
Numerical Analysis Lecture 37.
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L2.
5.3 Higher-Order Taylor Methods
Numerical Analysis Lecture 38.
MATH 175: NUMERICAL ANALYSIS II
Numerical solution of first-order ordinary differential equations
Adaptive Methods and Stiff Systems
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L6.
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L3 KFUPM.
Ch5 Initial-Value Problems for ODE
Sec 23: Runge–Kutta Methods
Numerical Analysis Lecture 36.
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L7 KFUPM.
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L1 KFUPM.
Numerical solution of first-order ordinary differential equations 1. First order Runge-Kutta method (Euler’s method) Let’s start with the Taylor series.
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L6 KFUPM.
Modeling and Simulation: Exploring Dynamic System Behaviour
Presentation transcript:

Sec:5.4 RUNGE-KUTTA METHODS

Sec:5.4 RUNGE-KUTTA METHODS 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method Computational Examples MATLAB Derivations

Sec:5.4 RUNGE-KUTTA METHODS Initial Value Problem Euler’s Method 𝑦 ′ =𝑓 𝑡,𝑦 𝑦(𝑎) =𝛼 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑤 0 =𝛼 𝑎≤ 𝑡 ≤𝑏, Modified Euler Method Euler’s Method 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 2 𝑲 𝟏 + 𝑲 𝟐 𝑤 0 =𝛼 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ 𝑲 𝟏 𝑤 0 =𝛼 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 +ℎ, 𝑤 𝑖 + 𝑲 𝟏 ℎ Modified Euler Method 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 2 𝒇 𝒕 𝒊 , 𝒘 𝒊 +𝑓 𝑡 𝑖 +ℎ, 𝑤 𝑖 +ℎ𝒇 𝒕 𝒊 , 𝒘 𝒊 𝑤 0 =𝛼

Sec:5.4 RUNGE-KUTTA METHODS Modified Euler Method Example 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 2 𝑲 𝟏 + 𝑲 𝟐 𝑤 0 =𝛼 Use the Modified Euler method h = 0.5, to approximate 𝑦(1) 𝑦 ′ =𝑦− 𝑡 2 +1 0≤ 𝑡 ≤4, 𝑦(0) = 0.5 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 +ℎ, 𝑤 𝑖 + 𝑲 𝟏 ℎ 𝑓(𝑡,𝑦)=𝑦− 𝑡 2 +1 𝑲 𝟏 =𝑓 𝑡 1 , 𝑤 1 𝑲 𝟏 =𝑓 𝑡 0 , 𝑤 0 =𝑓 0.5,1.375 =2.125 𝑲 𝟐 =𝑓 𝑡 1 +ℎ, 𝑤 1 + 𝑲 𝟏 ℎ =𝑓 0,0.5 =1.5 =𝑓 1,1.375+𝟐.𝟏𝟐𝟓∗0.5 𝑲 𝟐 =𝑓 𝑡 0 +ℎ, 𝑤 0 + 𝑲 𝟏 ℎ =2.4375 =𝑓 0.5,0.5+𝟏.𝟓∗0.5 =2 𝒘 𝟐 =𝟏.𝟑𝟕𝟓+ 𝟏 𝟐 ∗𝟐.𝟏𝟐𝟓 + 𝟏 𝟐 ∗𝟐.𝟒𝟑𝟕𝟓 𝟎.𝟓 𝑤 1 =0.5+ 1 2 ∗𝟏.𝟓+ 1 2 ∗𝟐 0.5 𝑤 2 =2.515625 𝑤 1 =1.375 →𝒚(𝟏)≈𝟐.𝟓𝟏𝟓𝟔𝟐𝟓 →𝒚(𝟎.𝟓)≈𝟏.𝟑𝟕𝟓

Sec:5.4 RUNGE-KUTTA METHODS 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method

Sec:5.4 RUNGE-KUTTA METHODS Example Midpoint method Use the Midpoint method h = 0.5, to approximate 𝑦(0.5) 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ𝑲 𝟐 𝑤 0 =𝛼 𝑦 ′ =𝑦− 𝑡 2 +1 0≤ 𝑡 ≤4, 𝑦(0) = 0.5 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 + ℎ 2 , 𝑤 𝑖 + ℎ 2 𝑲 𝟏 Midpoint method 𝑤 𝑖+1 = 𝑤 𝑖 +𝒉𝑓 𝑡 𝑖 + ℎ 2 , 𝑤 𝑖 + ℎ 2 𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑤 0 =𝛼 𝑲 𝟐 =𝑓 𝑡 0 +0.5∗ℎ, 𝑤 0 + 0.5∗𝑲 𝟏 ℎ 𝑓(𝑡,𝑦)=𝑦− 𝑡 2 +1 𝑲 𝟏 =𝑓 𝑡 0 , 𝑤 0 =𝑓 0.5,0.5+0.5∗𝟏.𝟓∗0.5 =1.8125 =𝑓 0,0.5 =1.5 𝑤 1 =0.5+ 𝟏.𝟖𝟏𝟐𝟓 0.5 =1.40625 →𝒚(𝟎.𝟓)≈𝟏.𝟒𝟎𝟔𝟐𝟓

Sec:5.4 RUNGE-KUTTA METHODS 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method

Sec:5.4 RUNGE-KUTTA METHODS Heun's Method Example 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 4 𝑲 𝟏 +3 𝑲 𝟑 𝑤 0 =𝛼 Use the Heun's method with h = 0.2, to approximate 𝑦(0.2) 𝑦 ′ =𝑦− 𝑡 2 +1 0≤ 𝑡 ≤2, 𝑦(0) = 0.5 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 + ℎ 3 , 𝑤 𝑖 + ℎ 3 𝑲 𝟏 𝑲 𝟑 =𝑓 𝑡 𝑖 + 2ℎ 3 , 𝑤 𝑖 + 2ℎ 3 𝑲 𝟐 𝑓(𝑡,𝑦)=𝑦− 𝑡 2 +1 𝑲 𝟑 =𝑓 𝑡 0 +2/15, 𝑤 0 +(2/15)(1.5956) 𝑲 𝟏 =𝑓 𝑡 0 , 𝑤 0 =1.694969 =𝑓 0,0.5 =1.5 𝑤 1 =0.5+ 0.2 4 𝟏.𝟓+3∗𝟏.694969 𝑲 𝟐 =𝑓 𝑡 0 +1/15, 𝑤 0 +1.5/15 =1.5956 𝑤 1 =0.82924 →𝒚(𝟎.𝟐)≈𝟎.𝟖𝟐𝟗𝟐𝟒

Sec:5.4 RUNGE-KUTTA METHODS 𝑶(𝒉) 1) Euler Method 𝑶( 𝒉 𝟐 ) 2) Modified Euler Method 𝑶( 𝒉 𝟐 ) 3) Midpoint Method 𝑶( 𝒉 𝟑 ) 4) Heun's Method 𝑶( 𝒉 𝟒 ) 5) RK4 Method

Sec:5.4 RUNGE-KUTTA METHODS Modified Euler Method Euler’s Method 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ 𝑲 𝟏 𝑤 0 =𝛼 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 2 𝑲 𝟏 + 𝑲 𝟐 𝑤 0 =𝛼 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 Heun's Method 𝑲 𝟐 =𝑓 𝑡 𝑖 +ℎ, 𝑤 𝑖 + 𝑲 𝟏 ℎ 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 4 𝑲 𝟏 +3 𝑲 𝟑 𝑤 0 =𝛼 Midpoint method 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ𝑲 𝟐 𝑤 0 =𝛼 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 + ℎ 3 , 𝑤 𝑖 + ℎ 3 𝑲 𝟏 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 + ℎ 2 , 𝑤 𝑖 + ℎ 2 𝑲 𝟏 𝑲 𝟑 =𝑓 𝑡 𝑖 + 2ℎ 3 , 𝑤 𝑖 + 2ℎ 3 𝑲 𝟐

Sec:25.3 RUNGE-KUTTA METHODS clear; clc; f=@(t,y) y-t.^2+1; h=0.2; alpha = 0.5; tspan = 0:h:4 [w] = midpoint(f,tspan,alpha); [tspan;w]' plot(tspan,w, '-ro'); grid on function [w] = midpoint(f,tspan,alpha) w(1)=alpha; t(1)=tspan(1); n1=length(tspan)-1; h=tspan(2)-tspan(1); for i=1:n1 K1 = f(t(i),w(i)); K2 = f(t(i)+0.5*h,w(i)+0.5*h*K1) w(i+1)=w(i)+(K2)*h t(i+1)=t(i)+h; end; end

Sec:5.4 RUNGE-KUTTA METHODS 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method Computational Examples MATLAB Derivations

Fourth-Order Runge-Kutta Methods Sec:25.3 RUNGE-KUTTA METHODS 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏 The most popular method is the fourth order Runge-Kutta method, or RK4 method Fourth-Order Runge-Kutta Methods 𝑊 𝑖+1 = 𝑊 𝑖 + 𝟏 𝟔 𝑲 𝟏 + 𝟐𝑲 𝟐 + 𝟐𝑲 𝟑 + 𝑲 𝟒 𝑊 0 =𝛼 𝑲 𝟏 =ℎ 𝐹 𝑡 𝑖 , 𝑊 𝑖 𝑲 𝟐 =ℎ 𝐹 𝑡 𝑖 + ℎ 2 , 𝑊 𝑖 + 1 2 𝑲 𝟏 𝑲 𝟑 =ℎ 𝐹 𝑡 𝑖 + ℎ 2 , 𝑊 𝑖 + 1 2 𝑲 𝟐 𝑲 𝟒 =ℎ 𝐹 𝑡 𝑖+1 , 𝑊 𝑖 + 𝑲 𝟑

Fourth-Order Runge-Kutta Methods Sec:5.4 RUNGE-KUTTA METHODS Fourth-Order Runge-Kutta Methods Example Use the RK4 method with h = 0.2, to approximate 𝑦(0.2) 𝑊 𝑖+1 = 𝑊 𝑖 + 𝟏 𝟔 𝑲 𝟏 + 𝟐𝑲 𝟐 + 𝟐𝑲 𝟑 + 𝑲 𝟒 𝑊 0 =𝛼 𝑲 𝟏 =ℎ 𝐹 𝑡 𝑖 , 𝑊 𝑖 𝑦 ′ =𝑦− 𝑡 2 +1 0≤ 𝑡 ≤2, 𝑦(0) = 0.5 𝑲 𝟐 =ℎ 𝐹 𝑡 𝑖 + ℎ 2 , 𝑊 𝑖 + 1 2 𝑲 𝟏 𝑲 𝟑 =ℎ 𝐹 𝑡 𝑖 + ℎ 2 , 𝑊 𝑖 + 1 2 𝑲 𝟐 𝑲 𝟒 =ℎ 𝐹 𝑡 𝑖+1 , 𝑊 𝑖 + 𝑲 𝟑

Sec:5.4 RUNGE-KUTTA METHODS

Implicit Euler’s Method Explicit Euler’s Method Sec:5.4 RUNGE-KUTTA METHODS Explicit and Implicit Euler Implicit Euler’s Method called implicit because the unknown appears on both sides of the equation. 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝒊+𝟏 , 𝑤 𝒊+𝟏 𝑤 0 =𝛼 Example Use Implicit Euler’s method with h = 1, to approximate 𝑦(2) Explicit Euler’s Method 𝑦 ′ = 𝑡 1+ 𝑦 2 1≤ 𝑡 ≤4, 𝑦(1) =1 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝒊 , 𝑤 𝒊 𝑤 0 =𝛼 Implicit Euler 𝑤 𝑖+1 = 𝑤 𝑖 + ℎ 𝑡 𝑖+1 1+ 𝑤 𝑖+1 2 𝑤 1 =1+ 2 1+ 𝑤 1 2 you need to solve nonlinear equation

Sec:5.4 RUNGE-KUTTA METHODS Explicit and Implicit Euler Explicit Euler’s Method 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝒊 , 𝑤 𝒊 𝑤 0 =𝛼 Implicit Euler’s Method Implicit 2ed order Method Implicit 2ed order Method 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ 𝟏 𝟐 𝑓 𝑡 𝒊 , 𝑤 𝒊 + 𝟏 𝟐 𝑓 𝑡 𝒊+𝟏 , 𝑤 𝒊+𝟏 𝑤 0 =𝛼 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝒊+𝟏 , 𝑤 𝒊+𝟏 𝑤 0 =𝛼 predictor-corrector method we will use a predicted value, 𝒘 𝒊+𝟏 ∗ obtained with Explicit Euler to evaluate an approximation to the value 𝒘 𝒊+𝟏 at the new point. Predictor: 𝒘 𝒊+𝟏 ∗ = 𝑤 𝑖 +ℎ𝑓 𝑡 𝒊 , 𝑤 𝒊 𝒘 𝒊+𝟏 = 𝑤 𝑖 +ℎ 𝟏 𝟐 𝑓 𝑡 𝒊 , 𝑤 𝒊 + 𝟏 𝟐 𝑓 𝑡 𝒊+𝟏 , 𝒘 𝒊+𝟏 ∗ Corrector:

Sec:5.4 RUNGE-KUTTA METHODS ODE Solver in MATLAB Ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb, ode15i, Example Example 𝑦 ′ =𝒚− 𝒕 𝟐 +𝟏 𝟎≤ 𝒕 ≤𝟒, 𝑦(0) = 𝟎.𝟓 [t,y] = ode23(odefun,tspan,y0) [t,y]=ode23(@(t,y) y-t^2+1,[0 4],0.5); plot(t,y);grid on

Sec:5.4 RUNGE-KUTTA METHODS ODE Solver in MATLAB Ode45, ode23, ode113, ode15s, ode23s, ode23t, ode23tb, ode15i, Example Example 𝒚 𝟏 ′ = 𝒚 𝟐 [t,y] = ode45(odefun,tspan,y0) 𝒚 𝟐 ′ = 𝟏− 𝒚 𝟏 𝟐 𝒚 𝟐 − 𝒚 𝟐 𝟎≤ 𝒕 ≤𝟐𝟎, 𝒚 𝟏 (𝟎) 𝒚 𝟐 (𝟎) = 𝟐 𝟎 F = @(t,y) [y(2); (1-y(1)^2)*y(2)-y(1)]; [t,y] = ode45(F,[0 20],[2; 0]); plot(t,y(:,1),'-o',t,y(:,2),'-o')

Sec:25.3 RUNGE-KUTTA METHODS Solver Problem Type Accuracy When to Use ode45 Nonstiff Medium Most of the time. ode45 should be the first solver you try. ode23 Low ode23 can be more efficient than ode45 at problems with crude tolerances, or in the presence of moderate stiffness. Low to High ode113 can be more efficient than ode45 at problems with stringent error tolerances, or when the ODE function is expensive to evaluate. ode113 ode15s Stiff Low to Medium Try ode15s when ode45 fails or is inefficient and you suspect that the problem is stiff. Also use ode15s when solving differential algebraic equations (DAEs). ode23s can be more efficient than ode15s at problems with crude error tolerances. It can solve some stiff problems for which ode15s is not effective. ode23s computes the Jacobian in each step, so it is beneficial to provide the Jacobian via odesetto maximize efficiency and accuracy. If there is a mass matrix, it must be constant. ode23s ode23t Use ode23t if the problem is only moderately stiff and you need a solution without numerical damping.  ode23t can solve differential algebraic equations (DAEs). ode23tb Like ode23s, the ode23tb solver might be more efficient than ode15s at problems with crude error tolerances. ode15i Fully implicit Use ode15i for fully implicit problems f(t,y,y’) = 0 and for differential algebraic equations (DAEs) of index 1. Sec:25.3 RUNGE-KUTTA METHODS

Sec:5.4 RUNGE-KUTTA METHODS

Sec:5.4 RUNGE-KUTTA METHODS The motion of a swinging pendulum under certain simplifying assumptions is described by the second-order differential equation 𝒅 𝟐 𝜽 𝒅 𝒕 𝟐 + 𝒈 𝑳 𝐬𝐢𝐧 𝜽=𝟎 where L=2 is the length of the pendulum, g ≈ 32.17 ft/s2 is the gravitational constant of the earth, and θ is the angle the pendulum makes with the vertical. If, in addition, we specify the position of the pendulum when the motion begins, 𝜃( 𝑡 0 ) = 𝜋 6 , and its velocity at that point, 𝜃′( 𝑡 0 ) =0, we have what is called an initial-value problem. Use midpoint method with h = 0.1 s, compute the angle θ obtained for this initial-value problems at t = 0, 1, and 2 s.

Convert into system of 1st order ode Sec:5.4 RUNGE-KUTTA METHODS 𝒅 𝟐 𝜽 𝒅 𝒕 𝟐 + 𝒈 𝑳 𝐬𝐢𝐧 𝜽=𝟎 Convert into system of 1st order ode 𝑦 1 =𝜃 𝑦 2 = 𝑑𝜃 𝑑𝑡 𝑑 𝑦 1 𝑑𝑡 = 𝑑𝜃 𝑑𝑡 𝑑 𝑦 2 𝑑𝑡 = 𝑑 2 𝜃 𝑑 𝑡 2 𝑑 𝑦 1 𝑑𝑡 = 𝑦 2 𝑑 𝑦 2 𝑑𝑡 =− 𝑔 𝐿 sin 𝑦 1 𝑌′ 𝑡 = 𝑑 𝑦 1 𝑑𝑡 𝑑 𝑦 2 𝑑𝑡 𝑌 𝑡 = 𝑦 1 (𝑡) 𝑦 2 (𝑡) 𝑌′ 𝑡 =𝐹(𝑡,𝑌) 𝜃(0) = 𝜋 6 𝐹 𝑡,𝑌 = 𝑦 2 − 𝑔 𝐿 sin 𝑦 1 𝜃′(0) =0 𝑌 0 = 𝜋/6 0

Sec:5.4 RUNGE-KUTTA METHODS 𝒅 𝟐 𝜽 𝒅 𝒕 𝟐 + 𝒈 𝑳 𝐬𝐢𝐧 𝜽=𝟎 𝑌′ 𝑡 =𝐹(𝑡,𝑌) 𝐹 𝑡,𝑌 = 𝑦 2 − 𝑔 𝐿 sin 𝑦 1 𝜽(𝟎) = 𝝅 𝟔 𝜽′(𝟎) =𝟎 𝑌 0 = 𝜋/6 0 Midpoint method 𝑊 𝑖+1 = 𝑊 𝑖 + 𝑲 𝟐 ℎ 𝑊 0 =𝛼 𝑊 𝑖 is a vector of size 2×1 𝑲 𝟏 , 𝑲 𝟐 and 𝜶 are vector of size 2×1 𝑲 𝟏 =𝐹 𝑡 𝑖 , 𝑊 𝑖 ℎ and 𝑡 𝑖 are scalars 𝑲 𝟐 =𝐹 𝑡 𝑖 + 1 2 ℎ, 𝑊 𝑖 + 1 2 𝑲 𝟏 ℎ 𝐹: 𝑡, 𝑦 1 𝑦 2 →

Remark: use this modified for system Sec:5.4 RUNGE-KUTTA METHODS Midpoint method clear; clc; L = 2; g=32.17; F=@(t,Y) [ Y(2) ; ... -(g/L)*sin(Y(1))]; t0=0; tf=2; n=1000; h=(tf-t0)/n; alpha = [ pi/6 ; 0 ]; tspan = t0:h:tf; [w] = midpoint(F,tspan,alpha); [tspan',w']; plot(tspan,w(1,:));grid on 𝑊 𝑖+1 = 𝑊 𝑖 + 𝑲 𝟐 ℎ 𝑊 0 =𝛼 𝑲 𝟏 =𝐹 𝑡 𝑖 , 𝑊 𝑖 𝑲 𝟐 =𝐹 𝑡 𝑖 + 1 2 ℎ, 𝑊 𝑖 + 1 2 𝑲 𝟏 ℎ function [w] = midpoint(f,tspan,alpha) w(:,1)=alpha; t(1)=tspan(1); n1=length(tspan)-1; h=tspan(2)-tspan(1); for i=1:n1 K1 = f(t(i),w(:,i)); K2 = f(t(i)+0.5*h,w(:,i)+0.5*h*K1); w(:,i+1)=w(:,i)+(K2)*h; t(i+1)=t(i)+h; end; end 𝑌′ 𝑡 =𝐹(𝑡,𝑌) 𝐹 𝑡,𝑌 = 𝑦 2 − 𝑔 𝐿 sin 𝑦 1 Remark: use this modified for system 𝑌 0 = 𝜋/6 0

Sec:5.4 RUNGE-KUTTA METHODS 𝒅 𝟐 𝜽 𝒅 𝒕 𝟐 + 𝒈 𝑳 𝐬𝐢𝐧 𝜽=𝟎 t(:) w(1,:) w(2,:) 0.0000 0.5236 0.0000 0.1000 0.4834 -0.8042 0.2000 0.3656 -1.4940 0.3000 0.1874 -1.9553 0.4000 -0.0231 -2.0993 0.5000 -0.2312 -1.8939 0.6000 -0.4021 -1.3790 0.7000 -0.5086 -0.6490 0.8000 -0.5343 0.1794 0.9000 -0.4754 0.9860 1.0000 -0.3400 1.6509 1.1000 -0.1481 2.0604 1.2000 0.0698 2.1329 1.3000 0.2775 1.8505 1.4000 0.4405 1.2688 1.5000 0.5331 0.4921 1.6000 0.5414 -0.3592 1.7000 0.4641 -1.1633 1.8000 0.3117 -1.7984 1.9000 0.1072 -2.1523 2.0000 -0.1166 -2.1517 𝜽(𝟎) = 𝝅 𝟔 𝜽′(𝟎) =𝟎 𝜽 𝜽′

Sec:5.4 RUNGE-KUTTA METHODS clear; clc; L = 2; g=32.17; F=@(t,Y) [ Y(2) ; ... -(g/L)*sin(Y(1))]; t0=0; tf=10; n=1000; h=(tf-t0)/n; alpha = [ pi/4 ; 0 ]; tspan = t0:h:tf; [w] = midpoint(F,tspan,alpha); [tspan',w']; plot(tspan,w(1,:));grid on function [w] = midpoint(f,tspan,alpha) w(:,1)=alpha; t(1)=tspan(1); n1=length(tspan)-1; h=tspan(2)-tspan(1); for i=1:n1 K1 = f(t(i),w(:,i)); K2 = f(t(i)+0.5*h,w(:,i)+0.5*h*K1); w(:,i+1)=w(:,i)+(K2)*h; t(i+1)=t(i)+h; end; end 𝑌′ 𝑡 =𝐹(𝑡,𝑌) 𝐹 𝑡,𝑌 = 𝑦 2 − 𝑔 𝐿 sin 𝑦 1 𝑌 0 = 𝝅/𝟒 0 𝒕 𝒇 =𝟏𝟎

Sec:5.4 RUNGE-KUTTA METHODS

Theorem 513 (nth Taylor polynomial in two variables) Sec:5.4 RUNGE-KUTTA METHODS nth Taylor polynomial in two variables 𝑓 𝑥 =𝑓 𝑥 0 +(𝑥− 𝑥 0 )𝑓′ 𝑥 0 + 1 2 (𝑥− 𝑥 0 ) 2 𝑓′′ 𝑥 0 + 1 6 (𝑥− 𝑥 0 ) 3 𝑓′′′ 𝑥 0 +⋯ Theorem 513 (nth Taylor polynomial in two variables) 1st derivatives 2ed nth derivatives

Sec:5.4 RUNGE-KUTTA METHODS 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏 Taylor’s Series Methods Initial Value Problem Euler’s Method 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑤 0 =𝛼 𝑦 ′ =𝑓 𝑡,𝑦 𝑦(𝑎) =𝛼 (*) 𝑎≤ 𝑡 ≤𝑏, We will use Taylor’s Theorem to derive Euler’s method. Suppose that 𝒚(𝒕), the unique solution to (*) Taylor’s Series Methods 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 + 𝒕 𝒊+𝟏 −𝒕 𝒊 𝒚 ′ 𝒕 𝒊 + 1 2 𝑡 𝑖+1 −𝑡 𝑖 𝟐 𝑦 ′′ 𝒕 𝒊 +⋯ 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 + 𝒕 𝒊+𝟏 −𝒕 𝒊 𝒚 ′ 𝒕 𝒊 + 𝑡 𝑖+1 −𝑡 𝑖 𝟐 𝑦 ′′ 𝜉 𝑖 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 +𝒉𝒚′ 𝒕 𝒊 + 1 2 𝒉 2 𝒚′′ 𝒕 𝒊 +⋯ 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 +𝒉𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 + 1 2 𝒉 𝟐 𝒇′ 𝒕 𝒊 ,𝑦 𝑡 𝑖 +⋯ 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 +𝒉𝒚′ 𝒕 𝒊 + 𝒉 2 𝑦 ′′ 𝜉 𝑖 𝒇 ′ 𝒕 𝒊 ,𝒚 𝒕 𝒊 = 𝝏 𝝏𝒕 𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 = 𝒇 𝒕 + 𝒇 𝒚 𝒚′ 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 +𝒉𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 + 𝒉 𝟐 𝑦 ′′ 𝜉 𝑖 𝑦 𝑡 𝑖+1 ≈𝑦 𝑡 𝑖 +𝒉𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 𝑦 𝑡 𝑖+1 =𝑦 𝑡 𝑖 +𝒉𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 + 1 2 𝒉 𝟐 𝒇 𝒕 + 𝒇 𝒚 𝒇 +⋯ 𝑤 𝑖+1 = 𝑤 𝑖 + 𝒉𝒇 𝒕 𝒊 , 𝒘 𝒊 𝑦 𝑡 𝑖+1 ≈𝑦 𝑡 𝑖 +𝒉𝒇 𝒕 𝒊 ,𝑦 𝑡 𝑖 + 1 2 𝒉 𝟐 𝒇 𝒕 + 𝒇 𝒚 𝒇 One way to reduce the error of Euler’s method would be to include higher-order terms of the Taylor series expansion in the solution. 𝑤 𝑖+1 = 𝑤 𝑖 +𝒉𝒇 𝒕 𝒊 , 𝑤 𝑖 + 1 2 𝒉 𝟐 𝒇 𝒕 + 𝒇 𝒚 𝒇 𝒕 𝒊 , 𝑤 𝑖 Higher-order derivatives become increasingly more complicated

Sec:5.4 RUNGE-KUTTA METHODS Taylor’s Series Methods 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏 Taylor’s Series Methods 𝒚 𝒕 𝒊+𝟏 =𝒚 𝒕 𝒊 +𝒉 𝒚 ′ 𝒕 𝒊 + 𝟏 𝟐 𝒉 𝟐 𝒚 ′′ 𝒕 𝒊 + 𝟏 𝟔 𝒉 𝟑 𝒚 ′′′ 𝒕 𝒊 +⋯ 𝒚 𝒕 𝒊+𝟏 =𝒚 𝒕 𝒊 +𝒉𝒇+ 𝟏 𝟐 𝒉 𝟐 𝒇 ′ + 𝟏 𝟔 𝒉 𝟑 𝒇 ′′ +⋯ 𝒚 𝒕 𝒊+𝟏 =𝒚 𝒕 𝒊 +𝒉 𝒇+ 𝟏 𝟐 𝒉 𝒇 ′ + 𝟏 𝟔 𝒉 𝟐 𝒇 ′′ +⋯ Taylor’s Series Method of order one 𝒚 𝒕 𝒊+𝟏 =𝒚 𝒕 𝒊 +𝒉 𝒇+ 𝟏 𝟐 𝒉 𝒇 ′ + 𝟏 𝟔 𝒉 𝟐 𝒇 ′′ +⋯ Euler’s Method Taylor’s Series Method of order two 𝒇 ′ = 𝒇 𝒕 + 𝒇 𝒚 𝒚′ = 𝒇 𝒕 + 𝒇 𝒚 𝒇 𝒕 𝒊 ,𝒚 𝒕 𝒊 𝒚 𝒕 𝒊+𝟏 =𝒚 𝒕 𝒊 +𝒉 𝒇+ 𝟏 𝟐 𝒉 𝒇 ′ + 𝟏 𝟔 𝒉 𝟐 𝒇 ′′ +⋯ 𝒘 𝒊+𝟏 = 𝒘 𝒊 +𝒉 𝒇+ 𝟏 𝟐 𝒉 𝒇 𝒕 + 𝟏 𝟐 𝒉𝒇 𝒇 𝒚 𝒕 𝒊 , 𝒘 𝒊

Taylor series in 2-dimension Sec:5.4 RUNGE-KUTTA METHODS Midpoint method Mod EulerMethod 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ 1 2 𝑲 𝟏 + 1 2 𝑲 𝟐 𝑤 𝑖+1 = 𝑤 𝑖 +ℎ 𝑲 𝟐 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟏 =𝑓 𝑡 𝑖 , 𝑤 𝑖 𝑲 𝟐 =𝑓 𝑡 𝑖 + 1 2 ℎ, 𝑤 𝑖 + 1 2 𝑲 𝟏 ℎ 𝑲 𝟐 =𝑓 𝑡 𝑖 +ℎ, 𝑤 𝑖 + 𝑲 𝟏 ℎ 𝑲 𝟏 =𝒇 𝒕 𝒊 , 𝒘 𝒊 Taylor’s Series Method of order two 𝑲 𝟐 =𝒇 𝒕 𝒊 + 𝒑 𝟏 𝒉, 𝒘 𝒊 + 𝒒 𝟏𝟏 𝑲 𝟏 𝒉 𝒘 𝒊+𝟏 = 𝒘 𝒊 +𝒉 𝒇+ 𝟏 𝟐 𝒉 𝒇 𝒕 + 𝟏 𝟐 𝒉𝒇 𝒇 𝒚 𝒕 𝒊 , 𝒘 𝒊 𝒘 𝒊+𝟏 = 𝒘 𝒊 +𝒉 𝒂 𝟏 𝑲 𝟏 + 𝒂 𝟐 𝑲 𝟐 Taylor series in 2-dimension + <2ed deriv>+⋯ =𝒇 𝒕 𝒊 , 𝒘 𝒊 + 𝒑 𝟏 𝒉 𝒇 𝒕 𝒕 𝒊 , 𝒘 𝒊 + 𝒒 𝟏𝟏 𝑲 𝟏 𝒉 𝒇 𝒚 𝒕 𝒊 , 𝒘 𝒊 𝑲 𝟐 𝒂 𝟏 𝑲 𝟏 + 𝒂 𝟐 𝑲 𝟐 = 𝒂 𝟏 𝒇+ 𝒂 𝟐 𝒇+ 𝒂 𝟐 𝒑 𝟏 𝒉 𝒇 𝒕 + 𝒂 𝟐 𝒒 𝟏𝟏 𝑲 𝟏 𝒉 𝒇 𝒚 +⋯ Matching the coefficients of f and its derivatives 𝒂 𝟐 𝒑 𝟏 = 𝟏 𝟐 𝒂 𝟐 𝒒 𝟏𝟏 = 𝟏 𝟐 𝒂 𝟏 + 𝒂 𝟐 =𝟏

Sec:5.4 RUNGE-KUTTA METHODS 𝑫𝒆𝒓𝒊𝒗𝒂𝒕𝒊𝒐𝒏 𝑲 𝟏 =𝒇 𝒕 𝒊 , 𝒘 𝒊 Matching the coefficients of f and its derivatives 𝑲 𝟐 =𝒇 𝒕 𝒊 + 𝒑 𝟏 𝒉, 𝒘 𝒊 + 𝒒 𝟏𝟏 𝑲 𝟏 𝒉 𝒂 𝟏 + 𝒂 𝟐 =𝟏 𝒘 𝒊+𝟏 = 𝒘 𝒊 +𝒉 𝒂 𝟏 𝑲 𝟏 + 𝒂 𝟐 𝑲 𝟐 𝒂 𝟐 𝒑 𝟏 = 𝟏 𝟐 three equations four unknown We have infinite number of solutions , there are an infinite number of second-order RK methods. 𝒂 𝟐 𝒒 𝟏𝟏 = 𝟏 𝟐 We present two of the most commonly used and preferred versions: 𝒂 𝟐 = 𝟏 𝟐 𝒂 𝟐 =𝟏 Modefied Euler Method Midpoint method

Sec:5.4 RUNGE-KUTTA METHODS