You are on page 1of 15

Calculo Numérico II

IF-392

Clase 05
Dr. Luis Sanchez
Adaptive Methods
Adaptive Runge Kutta Method
For an ODE with an
abrupt changing
solution, a constant
step size can represent
a serious limitation.

Use small step size in


high gradient region
(abrupt change)
automatic step size
adjustment
Adaptive Runge Kutta Method
1. First approach: Step halving
• Estimate local truncation error using two different
step sizes
• Solve each step twice, once as a full step and then as
two half steps

2. Second approach: Embedded RK methods


• (also called RK-Fehlberg methods)
• Estimate local truncation error between two
predictions using two different-order RK methods
1. Step Halving Method
 Step Halving (Adaptive RK) method
 Compute the solutions at each step twice using 4th-order
classic RK method
 Once as a full step h and independently as two half steps
(h/2)

 y1 – one full step; y2 – two half steps

  y2  y1
Error estimate

y2  y2  Correction – 5th-order
15
Exercise 01
Use the Step Halving Method in Octave to approximate the solutions
to the following initial-value problems. Compare the results to the
actual values.
2.1 Embedded Runge-Kutta Method
 Algorithm (Bogacki and Shampine, 1989; Shampine, 1994)
 Use 3rd-order & 4th-order RK methods simultaneously to
solve the ODE and estimate the error for step-size adjustment
 MATLAB function: ODE23
 OCTAVE function: ODE23

 k 1  f ( t i , yi )

1  1 1
yi  1  yi  ( 2 k1  3 k2  4 k3 ) h ; k2  f ( t i  h, yi  k1 h)
9  2 2
 3 3
 k 3  f ( x i  h, y i  k2 h)
4 4

1
Ei1  ( 5 k 1  6 k 2  8 k 3  9 k 4 ) h ; k 4  f ( t i  1 , yi  1 )
72

 Error estimate (Note: k1 is the same as k4 from previous step)


Embedded RK Method: ODE23
 Uses only three function evaluations (k1, k2, k3)
 After each step, the error is checked to determine
whether it is within desired tolerance. If it is, yi+1 is
accepted and k4 becomes k1 for the next time step
 If the error is too large, the step is repeated with a
reduced step sizes until the estimate error is acceptable

E  max( RelTol  y , AbsTol )


 RelTol: relative tolerance (default = 103)
 AbsTol: relative tolerance (default = 106)
Adaptive RK Method – ode23
• Exercise 02 : Use ode23 to solve the following ODE
from t = 0 to 4:

dy  ( t  2 ) 2 /[ 2 ( 0.075 ) 2 ]
 0.6 y  10 e ; y(0 )  0.5
dt

function yp = exercise02(t, y)
yp = 10*exp(-(t-2)*(t-2)/(2*0.075^2)) - 0.6*y;
endfunction
Exercise 02: ode23
>> options = odeset('RelTol',1.e-3); >> options = odeset('RelTol',1.e-4);
>> ode23('ex21_2', [0 4], 0.5, options); >> ode23('ex21_2', [0 4], 0.5,
options);

(a) RelTol = 103 (b) RelTol = 104


2.2. Runge-Kutta Fehlberg Method
 Fourth-order y i  1  yi  (
37
k1 
250
k3 
125
k4 
512
k6 )h
378 621 594 1771
2825 18575 13525 277 1
 Fifth-order y i  1  yi  ( k1  k3  k4  k5  k6 )h
27648 48384 55296 14336 4

 k1  f ( xi , yi )
These coefficients were developed
 1 1
 k2  f ( xi  h, yi  k1h) by Cash and Karp (1990). Also
 5 5 called Cash-Karp RK Method
 3 3 9
 k3  f ( xi  h, yi  k1h  k2 h)


10 40 40
 3 3 9 6
 k4  f ( xi  h, yi  k1h  k2 h  k3h)
5 10 10 5

k  11 5
f ( xi  h, yi  k1h  k2 h 
70
k3 h 
35
k4 h)
 5 54 2 27 27

k  7 1631 175 575 44275 253
f ( xi  h, yi  k1h  k2 h  k3 h  k4 h  k5 h )


6
8 55296 512 13824 110592 4096
Runge-Kutta Fehlberg Method

• First, calculate yi+1 using 4th-order Runge-Kutta


Felberg method  (y1)4th
• Then, calculate yi+1 using 5th-order Runge-Kutta
Felberg method  (y2)5th
• Calculate Error Ea = (y2)5th - (y1)4th
• Adjust step size according to error estimate
Step Size Control
• Use step-halving or Runge-Kutta Fehlberg to
estimate the local truncation error
• Adjust the step size according to error estimate
• Increase the step size if the error is too small and
decrease it if the error is too large
• For fourth-order schemes

 new 0.2 if  present   new

hnew  hpresent ;  
 present 0.25 if  present   new

 new     Desired error value
Exercise 02 dy
 0.6 y  10 e  ( t  2 ) 2 /[ 2 ( 0.075 ) 2 ]
; y(0)  0.5
21.2 dt

Forcing function

Runge-Kutta-Fehlberg
method with adaptive
step size control t

small step size


around t = 2
solution

You might also like