0% found this document useful (0 votes)
10 views13 pages

5.4 Runge Kutta Method

This section introduces Runge-Kutta methods for solving initial value problems (IVPs), focusing on the Midpoint method and the fourth-order Runge-Kutta method (RK4). It outlines the accuracy of various methods, including Euler's method and modified versions, and provides examples of implementing these methods. The document emphasizes the high-order truncation errors of Runge-Kutta methods, making them suitable for obtaining accurate numerical solutions.

Uploaded by

vqqh5fnvfh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

5.4 Runge Kutta Method

This section introduces Runge-Kutta methods for solving initial value problems (IVPs), focusing on the Midpoint method and the fourth-order Runge-Kutta method (RK4). It outlines the accuracy of various methods, including Euler's method and modified versions, and provides examples of implementing these methods. The document emphasizes the high-order truncation errors of Runge-Kutta methods, making them suitable for obtaining accurate numerical solutions.

Uploaded by

vqqh5fnvfh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Sec:5.

RUNGE-KUTTA
METHODS
Sec:5.4 RUNGE-KUTTA METHODS

In this section, we aim to:

1. Introduce some Runge-Kutta methods for solving IVPs,


particularly the Midpoint method and the fourth-order Runge-
Kutta method.

2. Implement the Midpoint method and the fourth-order Runge-Kutta


method for solving IVPs through some examples.
Sec:5.4 RUNGE-KUTTA METHODS

In this section, we will use Runge-Kutta methods for solving the following IVP:

𝑎 ≤𝑡 ≤𝑏 ,

Runge-Kutta methods can be used to obtain accurate numerical solutions because


they have high-order truncation errors. They include the following methods:
• Euler’s method (First-order accurate, )
• Modified Euler’s method (Second-order accurate, )
• Midpoint method (Second-order accurate, )
• Third-order Runge-Kutta method RK3 (it has several variants including Heun’s
method, )
• Fourth-order Runge-Kutta method RK4 (it also has several variants, )

Note: Similar to Euler’s method, other Runge-kutta methods produce


approximations of the exact solution at discrete points of the domain known as
mesh points.
Sec:5.2 EULER’S METHOD

𝒃− 𝒂
𝒉=
𝒏

Midpoint method

( h
2
h
)
𝑤𝑖 +1=𝑤 𝑖 +𝒉 𝑓 𝑡 𝑖 + , 𝑤𝑖 + 𝑓 ( 𝑡 𝑖 , 𝑤𝑖 )
2
𝑤 0 =𝛼
Sec:5.4 RUNGE-KUTTA METHODS

Example Midpoint method

Use the Midpoint


method h = 0.5, to 𝑤 0 =𝛼
(
h
2
h
𝑤𝑖 +1=𝑤 𝑖 +𝒉 𝑓 𝑡 𝑖 + , 𝑤𝑖 + 𝑓 ( 𝑡 𝑖 , 𝑤𝑖 )
2 )
approximate
𝒘𝟎 𝒘𝟏 𝒘𝟐
2
𝒕𝟎 𝒕𝟏 𝒕𝟐 𝑓 (𝑡 , 𝑦)=𝑦 −𝑡 +1
0 0. 5 1 . 0

𝑓 ( 𝑡 0 ,¿𝑤 ) )=1.5
𝑓 ( 00, 0.5

( h
2
h
𝑓 𝑡 0 + ,𝑤 0 + 𝑓 ( 𝑡 0 ,𝑤 0 )
2 )
¿ 𝑓 ( 𝑡 0 +0.5 ∗ h ,𝑤 0 +0.5 ∗ 𝑓 (𝑡 0 ,𝑤 0) h )
Find

𝑤2 =2.597 ¿ 𝑓 ( 0.25,0.5+0.5∗𝟏.𝟓∗0.5 )= 𝑓 ( 0.25,0.875 )=1.8125


𝑤 1 =0 .5+ (𝟏 . 𝟖𝟏𝟐𝟓
1.40625 ) 0.5
→ 𝒚 (𝟎 . 𝟓)≈ 𝟏 . 𝟒𝟎𝟔𝟐𝟓
Sec:25.3 RUNGE-KUTTA METHODS

Example

Use the Midpoint clear;


f=@(t,y) y-t.^2+1;
method h = 0.5, to
h=0.5; alpha = 0.5;
approximate t = 0:h:4
[w] = midpoint(f,t,alpha);
[t;w]'
plot(t,w, '-ro'); grid on

function [w] = midpoint(f,t,alpha)


w(1)=alpha; n=length(t);
h=t(2)-t(1);
for i=1:n-1
w(i+1)=w(i)+h*f(t(i)+0.5*h,w(i)+0.5*h*f(t(i),w(i)));
end; end

Midpoint method

( h
2
h
𝑤𝑖 +1=𝑤 𝑖 +𝒉 𝑓 𝑡 𝑖 + , 𝑤𝑖 + 𝑓 ( 𝑡 𝑖 , 𝑤𝑖 )
2 )
Sec:5.4 RUNGE-KUTTA METHODS

Runge-Kutta Methods

𝑶 (𝒉)1) Euler Method

𝟐
𝑶 (𝒉3)) Midpoint Method

𝟒
𝑶 (𝒉 5)
) RK4 Method
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

𝑲 𝟏=h 𝐹 ( 𝑡 𝑖 , 𝑊 𝑖 )

(h
2
1
𝑲 𝟐=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟏
2 )
(h
2
1
𝑲 𝟑=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟐
2 )
𝑲 𝟒=h 𝐹 ( 𝑡 𝑖 +1 ,𝑊 𝑖 + 𝑲 𝟑 )
Sec:5.4 RUNGE-KUTTA METHODS

Example 𝒘𝟎 𝒘𝟏 𝒘𝟐
2
𝒕𝟎 𝒕𝟏 𝒕𝟐 𝑓 (𝑡 , 𝑦)=𝑦 −𝑡 +1
Use the RK4 method with
h = 0.2, to approximate 0 0. 2 0. 4

Fourth-Order Runge-
Kutta Methods

𝑲 𝟏=h 𝐹 ( 𝑡 𝑖 , 𝑊 𝑖 )

( h
2
1
𝑲 𝟐=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟏
2 )
( h
2
1
𝑲 𝟑=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟐
2 )
𝑲 𝟒= h 𝐹 ( 𝑡 𝑖 +1 ,𝑊 𝑖 + 𝑲 𝟑 )
Sec:5.4 RUNGE-KUTTA METHODS

Example 𝒘𝟎 𝒘𝟏 𝒘𝟐
2
𝒕𝟎 𝒕𝟏 𝒕𝟐 𝑓 (𝑡 , 𝑦)=𝑦 −𝑡 +1
Use the RK4 method with
h = 0.2, to approximate 0 0. 2 0. 4

Fourth-Order Runge-
Kutta Methods

𝑲 𝟏=h 𝐹 ( 𝑡 𝑖 , 𝑊 𝑖 )

( h
2
1
𝑲 𝟐=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟏
2 )
( h
2
1
𝑲 𝟑=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟐
2 )
𝑲 𝟒= h 𝐹 ( 𝑡 𝑖 +1 ,𝑊 𝑖 + 𝑲 𝟑 )
Sec:5.4 RUNGE-KUTTA METHODS

Example 𝒘𝟎 𝒘𝟏 𝒘𝟐 𝒘𝟑
2
Use the RK4 method with 𝒕𝟎 𝒕𝟏 𝒕𝟐 𝒕 𝟑 𝑓 (𝑡 , 𝑦)=𝑦 −𝑡 +1
h = 0.2, to approximate 0 0. 2 0. 4 0. 6

𝒘 𝟏 =𝟎 .𝟖𝟐𝟗𝟐

𝑲 𝟏=𝟎 . 𝟐 ( 𝟎 . 𝟖𝟐𝟗𝟐 −𝟎 . 𝟐𝟐 +𝟏 ) =𝟎 . 𝟑𝟓𝟕𝟖


𝑲 𝟐=𝟎 . 𝟐 𝒇 ( 𝟎 . 𝟑 ,𝟏 . 𝟎𝟎𝟖𝟏 )=𝟎 . 𝟑𝟖𝟑𝟔
Fourth-Order Runge-
Kutta Methods 𝑲 𝟑=𝟎 . 𝟐 𝒇 ( 𝟎 . 𝟑 ,𝟏 . 𝟎𝟐𝟏 )=𝟎 . 𝟑𝟖𝟔𝟐

𝑲 𝟒=𝟎 . 𝟐 𝒇 ( 𝟎 . 𝟒 , 𝟏 .𝟐𝟏𝟓𝟒 )=𝟎 . 𝟒𝟏𝟏𝟎

𝑲 𝟏=h 𝐹 ( 𝑡 𝑖 , 𝑊 𝑖 ) +2*0.3862+0.4110

( h
2
1
𝑲 𝟐=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟏
2 )
( h
2
1
𝑲 𝟑=h 𝐹 𝑡 𝑖 + , 𝑊 𝑖 + 𝑲 𝟐
2 )
𝑲 𝟒= h 𝐹 ( 𝑡 𝑖 +1 ,𝑊 𝑖 + 𝑲 𝟑 )
Sec:5.4 RUNGE-KUTTA METHODS

Example

Use the RK4 method


h = 0.2, to
approximate

2 𝑡
𝑦 𝑡 ( 𝑥)=( 𝑡 +1 ) − 0.5 𝑒

function [w] = rk4(f,t,alpha)


w(1)=alpha; n=length(t);
clear; h=t(2)-t(1);
f=@(t,y) y-t.^2+1; for i=1:n-1
h=0.2; alpha = 0.5;
K1= h*f(t(i),w(i));
t = 0:h:2
[w] = rk4(f,t,alpha); K2 = h*f(t(i)+0.5*h,w(i)+0.5*K1);
[t;w]' K3 = h*f(t(i)+0.5*h,w(i)+0.5*K2);
plot(t,w, '-ro'); grid on K4 = h*f(t(i+1),w(i)+K3);
w(i+1)=w(i)+(1/6)*(K1+2*K2+2*K3+K4);
end; end
Sec:5.4 RUNGE-KUTTA METHODS

Runge-Kutta Methods

𝑶 (𝒉)1) Euler Method

𝟐
𝑶 (𝒉3)) Midpoint Method

𝟒
𝑶 (𝒉 5)
) RK4 Method

You might also like