0% found this document useful (0 votes)
2K views9 pages

Second Order Runge-Kutta Method: Example

The document describes the second order Runge-Kutta method and provides an example of using it to solve the initial value problem dx/dt = 1 + x^2 + t^3, with x(1) = -4. It also shows the fourth order Runge-Kutta method through another example, solving dy/dx = 1 + y + x^2, with y(0) = 0.5, to find y(0.2) and y(0.4).

Uploaded by

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

Second Order Runge-Kutta Method: Example

The document describes the second order Runge-Kutta method and provides an example of using it to solve the initial value problem dx/dt = 1 + x^2 + t^3, with x(1) = -4. It also shows the fourth order Runge-Kutta method through another example, solving dy/dx = 1 + y + x^2, with y(0) = 0.5, to find y(0.2) and y(0.4).

Uploaded by

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

Second order Runge-Kutta Method

Example
Solve the following system to find x (1.02) using RK2
x (t )  1  x 2  t 3 , x (1)  4, h  0.01,   1

STEP 1 :
K1  h f (t0  1, x0  4)  0.01(1  x02  t03 )  0.18
K 2  h f (t0  h, x0  K1 )
 0.01(1  ( x0  0.18)2  (t0  .01)3 )  0.1662
x (1  0.01)  x (1)  K1  K 2  / 2
 4  (0.18  0.1662) / 2  3.8269
CISE301_Topic8L4&5 1
Second order Runge-Kutta Method
Example

STEP 2

K1  h f (t1  1.01, x1  3.8269)  0.01(1  x12  t13 )  0.1668


K 2  h f (t1  h, x1  K1 )
 0.01(1  ( x1  0.1668)2  (t1  .01)3 )  0.1546

x (1.01  0.01)  x (1.01)  K1  K 2 


1
2
1
 3.8269  (0.1668  0.1546)  3.6662
2

CISE301_Topic8L4&5 2
x (t )  1  x (t )  t , x (1)  4,
2 3

Solution for t  [1,2]


Using RK2,   1

CISE301_Topic8L4&5 3
Example
4th-Order Runge-Kutta Method RK4

dy
 1 y  x 2

dx
y (0)  0.5
h  0.2
Use RK 4 to compute y (0.2) and y (0.4)

CISE301_Topic8L4&5 4
Example: RK4
Problem :
dy
 1 y  x2 , y (0)  0.5
dx
Use RK 4 to find y (0.2), y (0.4)

CISE301_Topic8L4&5 5
4th Order Runge-Kutta RK4

k1  f ( xi , yi )
h 1
k2  f ( xi  , yi  k1h )
2 2
h 1
k3  f ( xi  , yi  k2h )
2 2
k4  f ( xi  h, yi  k3h )

yi 1  yi  k1  2k2  2k3  k4 


h
6
Local error is O ( h5 ) and global error is O ( h 4 )
CISE301_Topic8L4&5 6
Example: RK4 See RK4 Formula
Problem : h  0.2
dy
 1 y  x2 , y (0)  0.5 f ( x, y )  1  y  x 2
dx
x0  0, y0  0.5
Use RK 4 to find y (0.2), y (0.4)
k1  f ( x0 , y0 )  (1  y0  x02 )  1.5

k2  f ( x0  h, y0  k1h )  1   y0  0.15   x0  0.12  1.64


1 1
2 2
Step 1

k3  f ( x0  h, y0  k2h )  1   y0  0.164    x0  0.12  1.654


1 1
2 2
k4  f ( x0  h, y0  k3h )  1   y0  0.16545   x0  0.2 2  1.7908

y1  y0  k1  2k2  2k3  k4   0.8293


h
6
CISE301_Topic8L4&5 7
Example: RK4
Problem :
h  0.2
dy
 1 y  x2 , y (0)  0.5 f ( x, y )  1  y  x 2
dx
x1  0.2, y1  0.8293
Use RK 4 to find y (0.2), y (0.4)
k1  f ( x1 , y1 )  1.7893
1 1
k2  f ( x1  h, y1  k1h )  1.9182
2 2
Step 2

1 1
k3  f ( x1  h, y1  k2h )  1.9311
2 2
k4  f ( x1  h, y1  k3h )  2.0555

y2  y1 
0.2
k1  2k2  2k3  k4   1.2141
6
CISE301_Topic8L4&5 8
Example: RK4
Problem :
dy
 1 y  x2 , y (0)  0.5
dx
Use RK 4 to find y (0.2), y (0.4)

Summary of the solution


xi yi
0.0 0.5
0.2 0.8293
0.4 1.2141
CISE301_Topic8L4&5 9

You might also like