Presentation is loading. Please wait.

Presentation is loading. Please wait.

ODEs: Adaptive Methods and Stiff Systems

Similar presentations


Presentation on theme: "ODEs: Adaptive Methods and Stiff Systems"— Presentation transcript:

1 ODEs: Adaptive Methods and Stiff Systems
Chapter 21 ODEs: Adaptive Methods and Stiff Systems

2 Adaptive Runge Kutta Method
Use small step size in high gradient region (abrupt change) automatic step size adjustment

3 Adaptive Runge Kutta Method
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 Second approach: Embedded RK methods (also called RK-Fehlberg methods) Estimate local truncation error between two predictions using two different-order RK methods

4 Step Halving Method y1 – one full step; y2 – two half steps
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 Error estimate Correction – 5th-order

5 Adaptive 4th-order RK Method
One full-step with h Two half-steps with h/2 Therefore, Two half-steps

6 Embedded Runge-Kutta Method
MATLAB function: ODE23 BS23 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 Error estimate (Note: k1 is the same as k4 from previous step)

7 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 RelTol: relative tolerance (default = 103) AbsTol: relative tolerance (default = 106)

8 Adaptive RK Method – ode23
Example 21.2: Use ode23 to solve the following ODE from t = 0 to 4: function yp = ex21_2(t, y) % Example 21.2 in the text book yp = 10*exp(-(t-2)*(t-2)/(2*0.075^2)) - 0.6*y;

9 (a) RelTol = 103 (b) RelTol = 104
Example 20.2: ode23 >> options = odeset('RelTol',1.e-3); >> ode23('ex21_2', [0 4], 0.5, options); >> options = odeset('RelTol',1.e-4); >> ode23('ex21_2', [0 4], 0.5, options); (a) RelTol = 10 (b) RelTol = 104

10 Other MATLAB Functions
MATLAB Function: ode45 Dormand and Prince (1990) Solve fourth- and fifth-order RK formulas simultaneously Make error estimates for step-size adjustment MATLAB Function: ode113 Adams-Bashforth-Moulton solver (order 1-12) Predictor-corrector method

11 Runge-Kutta Fehlberg Method
Fourth-order Fifth-order These coefficients were developed by Cash and Karp (1990). Also called Cash-Karp RK Method

12 Runge-Kutta Fehlberg Method
Identical coefficients (k1, k2, k3, k4, k5, k6) for both the fourth and fifth order Runge-Kutta-Fehlberg methods Save CPU time Error estimate – use two RK methods of different order to estimate the local truncation error

13 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

14 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

15 Step Size Adjustment For step size increases (RK4, n = 4)
For nth-order RK Method For step size increases (RK4, n = 4) For step size decreases, h is implicit in new Reduce hnew also reduce new

16 Example 21.2 Forcing function
Runge-Kutta-Fehlberg method with adaptive step size control t small step size around t = 2 solution t

17 Predator-Prey Equation
A simple predator-prey relationship is described by the Lotka-Volterra model, which we write in terms of a fox population f(t), with birth rate bf and death rate df and a geese population g(t) with birth rate bg and death rate dg

18 Predator-Prey Equation
Example: Given bf = 0.3, df = 0.8, bg = 1.2, dg = 0.6, find the populations of predators and preys as a function of time (t = 0 to 20) using ode45. Predator Prey function yp = predprey(t,y) % Fox (Predator) population y1(t), birth rate bf, death rate df % Geese (prey) poupulation y2(t), birth rate bg, death rate dg bf = 0.3; df = 0.8; bg = 1.2; dg = 0.6; yp = [y(1)*(bf*y(2)-df); y(2)*(bg-dg*y(1))];

19 Adaptive RK method : ode45
>> tspan=[0 20]; y0 = [1, 2]; >> [t,y] = ode45('predprey',tspan,y0); >> out = [t y] out =

20 Predator-Prey Model Time history of predator (fox) and prey (geese) populations

21 Predator-Prey Model State-space plot

22 Multistep Methods Runge-Kutta methods Multistep methods
-- one-step method -- use intermediate values between ti and ti+1 -- several evaluations of slope per step Multistep methods -- use values at ti , ti-1 , ti-2 etc -- only one evaluation of derivative per step

23 One-Step and Multistep Methods
One-step Multistep

24 Multi-step methods use several previous points (yi-1 , yi-2 ,…) in addition to the present point yi
- explicit (b0 = 0) & implicit methods. - # of the previous steps. Non-self start Huen method* Adams-Bashforth Methods (explicit methods b0 = 0) Admas-Moulton Methods (implicit methods) Predictor-Corrector Methods

25 Heun’s Method (Review)
Start with second-order method Look at Heun’s method (Self-Starting) Euler predictor - O(h2) Trapezoid corrector - O(h3)

26 Non-Self-Starting Heun’s Method
To improve predictor, use 3rd-order Euler method along with the same old corrector iterated until converged Note: are the final results of the corrector iterations at the previous time step

27 Non-Self Starting Heun’s Method
(a) 3rd-order predictor (b) 3rd-order corrector Non-self starting, need yi-1 and yi (two initial values)

28 Heun’s Method (a) 2nd-order predictor (b) 3rd-order corrector
Self-starting, need yi only

29 Truncation Errors Non-self-starting Heun method
Predictor truncation error Corrector truncation error

30 Modifiers Corrector Modifier Predictor Modifier (not used in textbook)
Error in textbook

31 Non-Self Starting Heun’s Method
So the sequence is Predict Adjust prediction* Correct Converged? If not, correct again

32 Hand Calculations Non-self-starting Heun’s method Need two initial conditions Example: 21.3 (p ) Exact solution: y = e 0.8t – e –0.5 t

33 Hand Calculations – First Step
Predictor: Corrector: First Step (i = 0) : need two initial conditions Predictor:

34 Hand Calculations – First Step
Corrector:

35 Hand Calculations – Second Step
Second Step (i = 1) : Predictor:

36 Hand Calculations – First Step
Corrector:

37 Stiffness A stiff system involves rapidly changing components (usually die away quickly) together with slowly ones Long-time solution is dominated by slow varying components

38 Numerical Stability Amplification or decay of numerical errors
A numerical method is stable if error incurred at one stage of the process do not tend to magnify at later stages Ill-conditioned differential equation -- numerical errors will be magnified regardless of numerical method Stiff differential equation -- require extremely small step size to achieve accurate results

39 Stability Example problem

40 Euler Explicit Method Stability criterion Region of absolute stability
Amplification factor

41 Unconditionally stable !
Euler Implicit Method Forward, Backward, or Centered Scheme? Unconditionally stable !

42 Unconditionally stable
Stability Explicit Euler method Second-order Adams-Moulton Implicit methods are in general more stable than explicit methods. If a = 1000, then h  to ensure stability Unconditionally stable

43 Example 21.5 Euler Explicit Euler Implicit

44 MATLAB Functions for Stiff Systems
ode15s – based on Gear backward differentiation for stiff problems of low to medium accuracy ode23s – based on modified Rosenbrock formula ode23t – trapezoidal rule with a free interpolant for moderately stiff problems without numerical damping ode23tb – implicit Runge-Kutta formula for more explanation please see page 529

45 Stiff ODE – van del Pol equation
Van der Pol equation for electronic circuit Convert to two first-order ODEs

46 Stiff ODE – van del Pol equation
M-file for van del Pol equation function yp = vanderpol(t,y,mu) % van der Pol equation for electronic circuit % d^2y1/dt^2 - mu*(1-y1^2) * dy1/dt + y1 = 0 % initial conditions, y1(0) = dy1/dt = 1 % convert to two first-order ODEs % The solution becomes progressively stiffer % as mu gets large yp = [y(2); mu*(1-y(1)^2)*y(2)-y(1)];

47 Nonstiff ODE – van del Pol equation
>> 20],[1 1],[], 1); >> H=plot(t,y(:,1),t,y(:,2),'m--'); >> legend('y1','y2',2);  = 1 ode45

48 Stiff ODE – van del Pol equation
>> 6000],[1 1],[], 1000); >> H=plot(t,y(:,1)); >> set(H,'LineWidth',3)  = 1000 ode23s

49 Bungee Jumper – Coupled ODEs
Vertical Dynamics of a jumper connected to a stationary platform with a bungee cord (Ex21.4) Air resistance depending on whether the cord is slack or stretched – use sign(v) for drag force Spring constant k (N/m) and damping coefficient  (N·s/m) Need to solve two simultaneous ODEs for x and v k =  = 0 if x  L

50 Non-stiff ODEs: Bungee Jumper
Use ode45 for non-stiff ODEs to solve for the distance and velocity of a bungee jumper function dydt = bungee(t,y,L,cd,m,k,gamma) g = 9.81; cord = 0; if y(1) > L % determine if the cord exerts a force cord = k/m * (y(1)-L) + gamma/m * y(2); end dydt = [y(2); g - sign(y(2)) * cd/m*y(2)^2 - cord];

51 Bungee jumper velocity Bungee jumper distance
>> [t,y] = 50],[0 0],[],30,0.25,68.1,40,8); >> h1 = plot(t,-y(:,1),t,y(:,2),'m--'); >> h2 = legend('x (m)','v(m/s)'); >> set(h1,'LineWidth',3); set(h2,'FontSize',12); Bungee jumper velocity Bungee jumper distance

52 CVEN 302-501 Homework No. 14 Chapter 21
Prob (30) (Hand Calculation) (30) Prob (40) (using MATLAB program except for part a)) Due 12/02/08 before 5:00 pm


Download ppt "ODEs: Adaptive Methods and Stiff Systems"

Similar presentations


Ads by Google