Uploaded by Galang Nurbudi Utomo

runge-kutta

advertisement
5.3.1 Modified Euler Method
Numerical solution of Initial Value Problem:
dY
= f (t, Y ) ⇔ Y (tn+1 ) = Y (tn ) +
dt
Z
tn+1
f (t, Y (t)) dt.
tn
5.3.1 Modified Euler Method
Numerical solution of Initial Value Problem:
dY
= f (t, Y ) ⇔ Y (tn+1 ) = Y (tn ) +
dt
Z
tn+1
f (t, Y (t)) dt.
tn
Approximate integral using the trapezium rule:
Y (tn+1 ) ≈ Y (tn ) +
h
[f (tn , Y (tn )) + f (tn+1 , Y (tn+1 ))] ,
2
tn+1 = tn + h.
5.3.1 Modified Euler Method
Numerical solution of Initial Value Problem:
dY
= f (t, Y ) ⇔ Y (tn+1 ) = Y (tn ) +
dt
Z
tn+1
f (t, Y (t)) dt.
tn
Approximate integral using the trapezium rule:
Y (tn+1 ) ≈ Y (tn ) +
h
[f (tn , Y (tn )) + f (tn+1 , Y (tn+1 ))] ,
2
tn+1 = tn + h.
Use Euler’s method to approximate Y (tn+1 ) ≈ Y (tn ) + hf (tn , Y (tn )) in
trapezium rule:
Y (tn+1 ) ≈ Y (tn ) +
h
[f (tn , Y (tn )) + f (tn+1 , Y (tn ) + hf (tn , Y (tn )))] .
2
5.3.1 Modified Euler Method
Numerical solution of Initial Value Problem:
dY
= f (t, Y ) ⇔ Y (tn+1 ) = Y (tn ) +
dt
Z
tn+1
f (t, Y (t)) dt.
tn
Approximate integral using the trapezium rule:
Y (tn+1 ) ≈ Y (tn ) +
h
[f (tn , Y (tn )) + f (tn+1 , Y (tn+1 ))] ,
2
tn+1 = tn + h.
Use Euler’s method to approximate Y (tn+1 ) ≈ Y (tn ) + hf (tn , Y (tn )) in
trapezium rule:
Y (tn+1 ) ≈ Y (tn ) +
h
[f (tn , Y (tn )) + f (tn+1 , Y (tn ) + hf (tn , Y (tn )))] .
2
Hence the modified Euler’s scheme
yn+1

K1 = hf (tn , yn )




h
K2 = hf (tn+1 , yn + K1 )
= yn + [f (tn , yn ) + f (tn+1 , yn + hf (tn , yn ))] ⇔

2


K1 + K2
 y
n+1 = yn +
2
5.3.1 Modified Euler Method — Local truncation error (1/3)
Local truncation error due to the approximation:
Y (tn+1 ) ≈ Y (tn ) +
1
(K1 + K2 )
2
where K1 = hf (tn , Y (tn )) and K2 = hf (tn + h, Y (tn ) + K1 ).
5.3.1 Modified Euler Method — Local truncation error (1/3)
Local truncation error due to the approximation:
Y (tn+1 ) ≈ Y (tn ) +
1
(K1 + K2 )
2
where K1 = hf (tn , Y (tn )) and K2 = hf (tn + h, Y (tn ) + K1 ).
Taylor Series of f (tn + h, Y (tn ) + K1 ) in two variables:
∂
∂
f (tn , Y (tn )) + O h2 , K12 .
K2 = h f (tn , Y (tn )) + h f (tn , Y (tn )) + K1
∂t
∂Y
5.3.1 Modified Euler Method — Local truncation error (1/3)
Local truncation error due to the approximation:
Y (tn+1 ) ≈ Y (tn ) +
1
(K1 + K2 )
2
where K1 = hf (tn , Y (tn )) and K2 = hf (tn + h, Y (tn ) + K1 ).
Taylor Series of f (tn + h, Y (tn ) + K1 ) in two variables:
∂
∂
f (tn , Y (tn )) + O h2 , K12 .
K2 = h f (tn , Y (tn )) + h f (tn , Y (tn )) + K1
∂t
∂Y
Since K1 = hf (tn , Y (tn )) = O(h),
1
(K1 + K2 ) = hf (tn , Y (tn ))
2
h2 ∂
∂
+
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3 ,
2 ∂t
∂Y
Expression to be compared with Taylor expansion of Y (tn+1 )
5.3.1 Modified Euler Method — Local truncation error (2/3)
Taylor Series of Y (tn+1 ) = Y (tn + h):
Y (tn + h) = Y (tn ) + hY 0 (tn ) +
h2 00
Y (tn ) + O h3 .
2
5.3.1 Modified Euler Method — Local truncation error (2/3)
Taylor Series of Y (tn+1 ) = Y (tn + h):
Y (tn + h) = Y (tn ) + hY 0 (tn ) +
Substitute Y 0 (tn ) = f (tn , Y (tn ))
h2 00
Y (tn ) + O h3 .
2
5.3.1 Modified Euler Method — Local truncation error (2/3)
Taylor Series of Y (tn+1 ) = Y (tn + h):
Y (tn + h) = Y (tn ) + hY 0 (tn ) +
h2 00
Y (tn ) + O h3 .
2
Substitute Y 0 (tn ) = f (tn , Y (tn )) and
Y 00 (tn ) =
d
f (t, Y (t))
dt
=
tn
∂
d
∂
f (tn , Y (tn )) +
Y (tn )
f (tn , Y (tn )),
∂t
dt
∂Y
∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )),
=
∂t
∂Y
5.3.1 Modified Euler Method — Local truncation error (2/3)
Taylor Series of Y (tn+1 ) = Y (tn + h):
Y (tn + h) = Y (tn ) + hY 0 (tn ) +
h2 00
Y (tn ) + O h3 .
2
Substitute Y 0 (tn ) = f (tn , Y (tn )) and
Y 00 (tn ) =
d
f (t, Y (t))
dt
=
tn
∂
d
∂
f (tn , Y (tn )) +
Y (tn )
f (tn , Y (tn )),
∂t
dt
∂Y
∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )),
=
∂t
∂Y
to get
Y (tn + h) = Y (tn ) + hf (tn , Y (tn ))
∂
h2 ∂
+
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3 .
2 ∂t
∂Y
(5.10)
5.3.1 Modified Euler Method — Local truncation error (3/3)
Now, the equations
Y (tn+1 ) = Y (tn ) + hf (tn , Y (tn ))
h2 ∂
∂
+
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3
2 ∂t
∂Y
5.3.1 Modified Euler Method — Local truncation error (3/3)
Now, the equations
Y (tn+1 ) = Y (tn ) + hf (tn , Y (tn ))
h2 ∂
∂
+
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3
2 ∂t
∂Y
and
1
(K1 + K2 ) = hf (tn , Y (tn ))
2
h2 ∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3
+
2 ∂t
∂Y
5.3.1 Modified Euler Method — Local truncation error (3/3)
Now, the equations
Y (tn+1 ) = Y (tn ) + hf (tn , Y (tn ))
h2 ∂
∂
+
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3
2 ∂t
∂Y
and
1
(K1 + K2 ) = hf (tn , Y (tn ))
2
h2 ∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3
+
2 ∂t
∂Y
1
imply that Y (tn+1 ) = Y (tn ) + (K1 + K2 ) + O h3 .
2
The local truncation error is τn = O h3 : the modified Euler method is second
order accurate. (A method is conventionally called p th order if the local
truncation error is of order p + 1.)
5.3.2 Second order Runge-Kutta schemes (1/3)
Modified Euler is an example of 2nd order R-K method.
5.3.2 Second order Runge-Kutta schemes (1/3)
Modified Euler is an example of 2nd order R-K method.
The general 2nd order Runge-Kutta scheme takes the form


K = hf (tn , yn );

 1
K2 = hf (tn + αh, yn + βK1 );


 y
=y +a K +a K .
n+1
n
1
1
2
2
(5.11)
5.3.2 Second order Runge-Kutta schemes (1/3)
Modified Euler is an example of 2nd order R-K method.
The general 2nd order Runge-Kutta scheme takes the form


K = hf (tn , yn );

 1
K2 = hf (tn + αh, yn + βK1 );


 y
=y +a K +a K .
n+1
n
1
1
2
(5.11)
2
Repeating the earlier analysis, K1 = hf (tn , Y (tn )) and
K2 = hf (tn , Y (tn ))
∂
∂
+ h2 α f (tn , Y (tn )) + βf (tn , Y (tn ))
f (tn , Y (tn )) + O(h3 );
∂t
∂Y
⇒ a1 K1 + a2 K2 = h(a1 + a2 )f (tn , Y (tn ))
∂
∂
+ a2 h2 α f (tn , Y (tn )) + βf (tn , Y (tn ))
f (tn , Y (tn )) + O(h3 ).
∂t
∂Y
5.3.2 Second order Runge-Kutta schemes (2/3)
Comparing
a1 K1 + a2 K2 = h(a1 + a2 )f (tn , Y (tn ))
∂
∂
2
f (tn , Y (tn )) + O(h3 )
+ a2 h α f (tn , Y (tn )) + βf (tn , Y (tn ))
∂t
∂Y
5.3.2 Second order Runge-Kutta schemes (2/3)
Comparing
a1 K1 + a2 K2 = h(a1 + a2 )f (tn , Y (tn ))
∂
∂
2
f (tn , Y (tn )) + O(h3 )
+ a2 h α f (tn , Y (tn )) + βf (tn , Y (tn ))
∂t
∂Y
with equation (5.10)
Y (tn+1 ) = Y (tn ) + hf (tn , Y (tn ))
h2 ∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3 ,
+
2 ∂t
∂Y
5.3.2 Second order Runge-Kutta schemes (2/3)
Comparing
a1 K1 + a2 K2 = h(a1 + a2 )f (tn , Y (tn ))
∂
∂
2
f (tn , Y (tn )) + O(h3 )
+ a2 h α f (tn , Y (tn )) + βf (tn , Y (tn ))
∂t
∂Y
with equation (5.10)
Y (tn+1 ) = Y (tn ) + hf (tn , Y (tn ))
h2 ∂
∂
f (tn , Y (tn )) + f (tn , Y (tn ))
f (tn , Y (tn )) + O h3 ,
+
2 ∂t
∂Y
one gets a second order scheme Y (tn+1 ) = Y (tn ) + a1 K1 + a2 K2 + O h3 if

 a1 + a2 = 1;
(5.12)
 αa2 = βa2 = 1 .
2
5.3.2 Second order Runge-Kutta Schemes (3/3)
General 2nd order Runge-Kutta scheme:


K = hf (tn , yn );

 1
K2 = hf (tn + αh, yn + βK1 );


 y
=y +a K +a K .
n+1
n
1
1
2
2
with

 a1 + a2 = 1;
 αa2 = βa2 = 1 .
2
Since we have 3 equations and 4 unknowns (a1 , a2 , α, β), there are infinitely
many solutions.
5.3.2 Second order Runge-Kutta Schemes (3/3)
General 2nd order Runge-Kutta scheme:


K = hf (tn , yn );

 1
K2 = hf (tn + αh, yn + βK1 );


 y
=y +a K +a K .
n+1
n
1
1
2
with
2

 a1 + a2 = 1;
 αa2 = βa2 = 1 .
2
Since we have 3 equations and 4 unknowns (a1 , a2 , α, β), there are infinitely
many solutions.
The most popular are,
I
Modified Euler: a1 = a2 = 1/2, α = β = 1.
⇒ K1 = hf (tn , yn ), K2 = hf (tn + h, yn + K1 ) and yn+1 = yn + (K1 + K2 )/2.
I
Midpoint method: a1 = 0, a2 = 1, α = β = 1/2.
⇒ K1 = hf (tn , yn ), K2 = hf (tn + h/2, yn + K1 /2) and yn+1 = yn + K2 .
I
Heun’s method: a1 = 1/4, a2 = 3/4, α = β = 2/3.
⇒ K1 = hf (tn , yn ), K2 = hf (tn + 2h/3, yn + 2K1 /3) and
yn+1 = yn + (K1 + 3K2 )/4.
5.3.3 Higher order Runge-Kutta methods
Schemes of the form (5.11) can be extended to higher order methods. The
most widely used Runge-Kutta scheme is the 4th order scheme RK4 based on
Simpson’s rule.
yn+1 = yn +
1
(K1 + 2K2 + 2K3 + K4 ),
6
where K1 = hf (tn , yn ),
h
K2 = hf tn + , yn +
2
h
K3 = hf tn + , yn +
2
K1
2
K2
2
,
(5.13)
,
K4 = hf (tn + h, yn + K3 ).
This scheme has local truncation error of order h5 , which can be checked in the
same way as the second order scheme, but involves rather messy algebra.
Download