
Understanding Runge-Kutta Methods for Numerical Integration
Explore various Runge-Kutta methods including Euler, Modified Euler, Midpoint, Heun's, and RK4. Learn how these methods are applied to solve initial value problems and see computational examples for a better understanding of numerical integration techniques.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Sec:5.4 RUNGE-KUTTA METHODS
Sec:5.4 RUNGE-KUTTA METHODS Runge-Kutta Methods 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method I. II. MATLAB III. Derivations Computational Examples
Sec:5.4 RUNGE-KUTTA METHODS Initial Value Problem Euler s Method ? = ? ?,? ?(?) = ? ??+1= ??+ ? ??,?? ?0 = ? ? ? ?, Modified Euler Method Euler s Method ??+1= ??+ ?0 = ? ??+1= ??+ ?? ?0 = ? ??+ ?? 2 ??= ? ??,?? ??= ? ??,?? ??= ? ??+ ,??+ ?? Modified Euler Method ??+1= ??+ ?0 = ? ? ??,?? + ? ??+ ,??+ ? ??,?? 2
Sec:5.4 RUNGE-KUTTA METHODS Modified Euler Method Example ??+1= ??+ ?0 = ? ??+ ?? Use the Modified Euler method h = 0.5, to approximate ?(1) 2 ? = ? ?2+ 1 0 ? 4, ?(0) = 0.5 ??= ? ??,?? ??= ? ??+ ,??+ ?? ?(?,?) = ? ?2+ 1 ??= ? ?1,?1 = ? 0.5,1.375 = 2.125 ??= ? ?0,?0 = ? 0,0.5 = 1.5 ??= ? ?1+ ,?1+ ?? = ? 1,1.375 + ?.??? 0.5 ??= ? ?0+ ,?0+ ?? = 2.4375 = ? 0.5,0.5 + ?.? 0.5 = 2 1 2 ?.? +1 ?1=1.375 ?(?.?) ?.??? ? ? ?.??? +? ??= ?.??? + ? ?.???? ?.? ?1= 0.5 + 2 ? 0.5 ?2=2.515625 ?(?) ?.??????
Sec:5.4 RUNGE-KUTTA METHODS 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,0.5 = 1.5 = ? 0.5,0.5 + 0.5 ?.? 0.5 = 1.8125 ?1= 0.5 + ?.???? 0.5 =1.40625 ?(?.?) ?.?????
Sec:5.4 RUNGE-KUTTA METHODS 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 ??+1= ??+ ?0 = ? Example 4??+ 3?? 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 = ? 0,0.5 = 1.5 = 1.694969 ?1= 0.5 +0.2 ?1=0.82924 ??= ? ?0+ 1/15,?0+ 1.5/15 ?.? + 3 ?.694969 4 ?(?.?) ?.????? = 1.5956
Sec:5.4 RUNGE-KUTTA METHODS 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= ??+ ?0 = ? ??+ ?? 2 ??= ? ??,?? ??= ? ??,?? Heun's Method ??+1= ??+ ?0 = ? ??= ? ??+ ,??+ ?? 4??+ 3?? Midpoint method ??= ? ??,?? ??+1= ??+ ?? ?0 = ? ??= ? ??+ 3,??+ 3?? ??= ? ??,?? ??= ? ??+ 2,??+ ??= ? ??+2 3,??+2 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 Runge-Kutta Methods 1) Euler Method 2) Modified Euler Method 3) Midpoint Method 4) Heun's Method 5) RK4 Method I. II. MATLAB III. Derivations Computational Examples
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,??+ ??
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 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 ? 4, ??+1= ??+ ? ??,?? ?0 = ? 1 + ?2 ?(1) = 1 Implicit Euler ??+1 1 + ??+1 2 1 + ?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 2ed order Method Implicit 2ed order Method Implicit Euler s Method ? ?? ??,?? +? ??+1= ??+ ? ??+?,??+? ?0 = ? ??+1= ??+ ?? ??+?,??+? ?0 = ? predictor-corrector method we will use a predicted value, ??+? to evaluate an approximation to the value ??+?at the new point. obtained with Explicit Euler ??+? = ??+ ? ??,?? 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')
Problem Type Nonstiff Solver Accuracy When to Use ode45 Medium Most of the time. ode45 should be the first solver you try. 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. Low to Medium suspect that the problem is stiff. Also use ode15s when solving differential algebraic equations (DAEs). Low 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. Low Use ode23t if the problem is only moderately stiff and you need a solution without numerical damping. ode23t can solve differential algebraic equations (DAEs). Low Like ode23s, the ode23tb solver might be more efficient than ode15s at problems with crude error tolerances. Low Use ode15i for fully implicit problems for differential algebraic equations (DAEs) of index 1. ode23 Low ode113 ode15s Stiff Try ode15s when ode45 fails or is inefficient and you Sec:25.3 RUNGE-KUTTA METHODS ode23s ode23t ode23tb ode15i Fully implicit = and
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) =? ? (?0) = 0, we have what is called an initial- value problem. 6, and its velocity at that point, Use midpoint method with h = 0.1 s, compute the angle obtained for this initial-value problems at t = 0, 1, and 2 s.
Sec:5.4 RUNGE-KUTTA METHODS ??? ???+? ????? = ? Convert into system of 1storder ode ??1 ??= ?2 ??1 ??=?? ?1= ? ?? ?2=?? ??2 ?? = ? =?2? ??2 ??2 ?? ?? ?sin?1 ??1 ?? ??2 ?? ?1(?) ?2(?) ? ? = ?(?,?) ? ? = ? ? = ?(0) =? ?2 ? 6 ? ?,? = ?sin?1 ? (0) = 0 ? 0 =?/6 0
Sec:5.4 RUNGE-KUTTA METHODS ??? ???+? ? ? = ?(?,?) ????? = ? ?2 ?(?) =? ? ? ?,? = ?sin?1 ? ? (?) = ? ? 0 =?/6 0 Midpoint method ??is a vector of size 2 1 ??+1= ??+ ?? ?0 = ? ??, ??and ? are vector of size 2 1 ??= ? ??,?? ??= ? ??+1 and ??are scalars 2 ,??+1 2?? ?1 ?2 ?: ?,
Sec:5.4 RUNGE-KUTTA METHODS Midpoint method clear; clc; L = 2; g=32.17; F=@(t,Y) [ Y(2) ; ... ??+1= ??+ ?? ?0 = ? -(g/L)*sin(Y(1))]; t0=0; tf=2; n=1000; h=(tf-t0)/n; alpha = [ pi/6 ; 0 ]; ??= ? ??,?? ??= ? ??+1 2 ,??+1 tspan = t0:h:tf; [w] = midpoint(F,tspan,alpha); [tspan',w']; plot(tspan,w(1,:));grid on 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 ??? ???+? ?(?) =? ????? = ? w(1,:) w(2,:) t(:) 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 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) 1stderivatives 2ed nth derivatives
Sec:5.4 RUNGE-KUTTA METHODS ?????????? Taylor s Series Methods Euler s Method ??+1= ??+ ? ??,?? ?0 = ? Initial Value Problem (*) ? = ? ?,? ?(?) = ? ? ? ?, 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 2?2? ?? + +1 2??? ??,? ?? ?? ?? + ??+1 ?? ? ??+1 = ? ?? + ?? ??,? ?? + ? ??+1 = ? ?? + ?? ?? + ?2? ?? ? ??? ??,? ?? + ??? ?? ? ??+1 = ? ?? + ?? ??,? ?? ? ??,? ?? = = ??+ ??? ? ??+1 ? ?? + ?? ??,? ?? +1 2????+ ??? + +1 2????+ ??? ? ??+1 = ? ?? + ?? ??,? ?? ??+1= ??+ ?? ??,?? ? ??+1 ? ?? + ?? ??,? ?? 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 ? = ??+ ??? = ??+ ??? ? ??+? = ? ?? + ? ? +? ?? ? +? ???? + ??,? ?? ??+?= ??+ ? ? +? ????+? ????? ??,??
Sec:5.4 RUNGE-KUTTA METHODS Midpoint method Mod EulerMethod ??+1= ??+ ?? 1 2??+1 ??+1= ??+ 2?? ??= ? ??,?? ??= ? ??+1 ??= ? ??,?? 2 ,??+1 2?? ??= ? ??+ ,??+ ?? ??= ? ??,?? ??= ? ??+ ???,??+ ?????? Taylor s Series Method of order two ??+?= ??+ ? ? +? ????+? ????? ??+?= ??+ ? ????+ ???? ??,?? ?? + <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: ??=? ??= ? ? Midpoint method Modefied Euler Method