21.06.2014 Views

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

☞ because we do not want to discard past timesteps, which could amount to tremendous waste of<br />

computational resources,<br />

☞ because it is inexpensive and it works for many practical problems,<br />

☞ because there is no reliable method that can deliver guaranteed accuracy for general IVP.<br />

“Recycle” heuristics already employed for adaptive quadrature, see Sect. 10.6:<br />

3 while ( ( t ( end ) < T ) ( h > hmin ) ) %<br />

4 yh = Psihigh ( h , y0 ) ; %<br />

5 yH = Psilow ( h , y0 ) ; %<br />

6 est = norm( yH−yh ) ; %<br />

7<br />

8 i f ( est < max( r e l t o l ∗norm( y0 ) , a b s t o l ) ) %<br />

9 y0 = yh ; y = [ y , y0 ] ; t = [ t , t ( end ) + min ( T−t ( end ) , h ) ] ; %<br />

10 h = 1.1∗h ; %<br />

11 else , h = h / 2 ; end %<br />

12 end<br />

Idea: Estimation of one-step error, cf. Sect. 10.6<br />

Compare two discrete evolutions Ψ h , ˜Ψ h of different order<br />

for current timestep h:<br />

If Order(˜Ψ) > Order(Ψ)<br />

⇒ Φ h y(t k ) − Ψ h y(t k ) ≈ EST<br />

} {{ } k := ˜Ψ h y(t k ) − Ψ h y(t k ) . (11.5.3)<br />

one-step error<br />

Heuristics for concrete h<br />

Ôº ½½º<br />

Comments on Code 11.5.2:<br />

• Input arguments:<br />

– Psilow, Psihigh: function handles to discrete evolution operators for autonomous ODE of<br />

different order, type @(y,h), expecting a state (column) vector as first argument, and a<br />

Ôº ½½º<br />

– h0: stepsize h 0 for the first timestep<br />

stepsize as second,<br />

– T: final time T > 0,<br />

– y0: initial state y 0 ,<br />

Compare<br />

Simple algorithm:<br />

EST k ↔ ATOL<br />

EST k ↔ RTOL ‖y k ‖<br />

absolute tolerance<br />

➣ Reject/accept current step (11.5.4)<br />

relative tolerance<br />

EST k < max{ATOL, ‖y k ‖RTOL}: Carry out next timestep (stepsize h)<br />

Use larger stepsize (e.g., αh with some α > 1) for following step<br />

(∗)<br />

EST k > max{ATOL, ‖y k ‖RTOL}: Repeat current step with smaller stepsize < h, e.g., 1 2 h<br />

Rationale for (∗): if the current stepsize guarantees sufficiently small one-step error, then it might<br />

be possible to obtain a still acceptable one-step error with a larger timestep, which would enhance<br />

efficiency (fewer timesteps for total numerical integration). This should be tried, since timestep control<br />

Ôº ½½º<br />

Code 11.5.3: simple local stepsize control for single step methods<br />

1 function [ t , y ] = odeintadapt ( Psilow , Psihigh , T , y0 , h0 , r e l t o l , abstol , hmin )<br />

2 t = 0 ; y = y0 ; h = h0 ; %<br />

will usually provide a safeguard against undue loss of accuracy.<br />

!<br />

– reltol, abstol: relative and absolute tolerances, see (11.5.4),<br />

– hmin: minimal stepsize, timestepping terminates when stepsize control h k < h min , which is<br />

relevant for detecting blow-ups or collapse of the solution.<br />

• line 3: check whether final time is reached or timestepping has ground to a halt (h k < h min ).<br />

• line 4, 5: advance state by low and high order integrator.<br />

• line 6: compute norm of estimated error, see (??).<br />

• line 8: make comparison (11.5.4) to decide whether to accept or reject local step.<br />

• line 9, 10: step accepted, update state and current time and suggest 1.1 times the current<br />

stepsize for next step.<br />

• line 11 step rejected, try again with half the stepsize.<br />

• Return values:<br />

– t: temporal mesh t 0 < t 1 < t 2 < . .. < t N < T , where t N < T indicated premature<br />

termination (collapse, blow-up),<br />

– y: sequence (y k ) N k=0 .<br />

By the heuristic considerations, see (11.5.3) it seems that EST k measures the one-step error<br />

for the low-order method Ψ and that we should use y k+1 = Ψ h ky k , if the timestep is<br />

accepted.<br />

Ôº¼ ½½º

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!