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.

Heuristics: the timestep h is small ➥ “higher order terms” O(h p+2 ) can be ignored.<br />

✎<br />

Ψ h ky(t k ) − Φ h . ky(t k ) = ch p+1<br />

k + O(h p+2<br />

k ) ,<br />

˜Ψ hk y(t k ) − Φ h . ky(t k ) = O(h p+2<br />

k ) .<br />

.<br />

notation: = equality up to higher order terms in h k<br />

⇒ EST k<br />

.<br />

= ch p+1<br />

k . (11.5.6)<br />

• line 9: compute presumably better local stepsize according to (11.5.9),<br />

• line 10: decide whether to repeat the step or advance,<br />

• line 11: extend output arrays if current step has not been rejected.<br />

.<br />

EST k = ch p+1<br />

k ⇒ c = . EST k<br />

h p+1 . (11.5.7)<br />

k<br />

△<br />

Available in algorithm, see (11.5.3)<br />

Remark 11.5.11 (Stepsize control in MATLAB).<br />

For the sake of accuracy (stipulates “EST k < TOL”) & efficiency (favors “>”) we aim for<br />

EST k<br />

!<br />

= TOL := max{ATOL, ‖y k ‖RTOL} . (11.5.8)<br />

Ψ ˆ= RK-method of order 4 ˜Ψ ˆ= RK-method of order 5<br />

ode45<br />

What timestep h ∗ can actually achieve (11.5.8), if we “believe” in (11.5.6) (and, therefore, in (11.5.7))?<br />

"‘Optimal timestep”:<br />

(stepsize prediction)<br />

(11.5.7) & (11.5.8) ⇒ TOL = EST k<br />

h p+1<br />

k<br />

h p+1<br />

∗ .<br />

h ∗ = h p+1 √ TOL<br />

EST k<br />

. (11.5.9)<br />

(A): In caseEST k > TOL ➣ repeat step with stepsize h ∗ .<br />

adjusted stepsize (A)<br />

suggested stepsize<br />

(B)<br />

Ôº¿ ½½º<br />

Specifying tolerances for MATLAB’s integrators:<br />

options = odeset(’abstol’,atol,’reltol’,rtol,’stats’,’on’);<br />

[t,y] = ode45(@(t,x) f(t,x),tspan,y0,options);<br />

(f = function handle, tspan ˆ= [t 0 , T], y0 ˆ= y 0 , t ˆ= t k , y ˆ= y k )<br />

Example 11.5.12 (Adaptive timestepping for mechanical problem).<br />

△<br />

Ôº ½½º<br />

(B): IfEST k ≤ TOL ➣ use h ∗ as stepsize for next step.<br />

Movement of a point mass in a conservative force field:<br />

t ↦→ y(t) ∈ R 2 ˆ= trajectory<br />

Code 11.5.10: refined local stepsize control for single step methods<br />

1 function [ t , y ] =<br />

o d e i n t s s c t r l ( Psilow , p , Psihigh , T , y0 , h0 , r e l t o l , abstol , hmin )<br />

2 t = 0 ; y = y0 ; h = h0 ; %<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 t o l = max( r e l t o l ∗norm( y ( : , end ) ) , a b s t o l ) ; %<br />

9 h = h∗max( 0 . 5 , min ( 2 , ( t o l / est ) ^ ( 1 / ( p+1) ) ) ) ; %<br />

10 i f ( est < t o l ) %<br />

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

12 end<br />

13 end<br />

Newton’s law:<br />

acceleration<br />

ÿ = F(y) := − 2y<br />

‖y‖ 2 . (11.5.10)<br />

2<br />

Equivalent 1st-order ODE, see Rem. 11.1.7: with velocity v := ẏ<br />

(ẏ ) ( ) v<br />

=<br />

˙v − 2y . (11.5.11)<br />

‖y‖ 2 2<br />

Initial values used in the experiment:<br />

y(0) :=<br />

( )<br />

−1<br />

0<br />

force<br />

( )<br />

0.1<br />

, v(0) :=<br />

−0.1<br />

Comments on Code 11.5.9 (see comments on Code 11.5.2 for more explanations):<br />

• Input arguments as for Code 11.5.2, except for p ˆ= order of lower order discrete evolution.<br />

Ôº ½½º<br />

Adaptive integrator: ode45(@(t,x) f,[0 4],[-1;0;0.1;-0.1,],options):<br />

➊ options = odeset(’reltol’,0.001,’abstol’,1e-5);<br />

➋ options = odeset(’reltol’,0.01,’abstol’,1e-3);<br />

Ôº ½½º

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

Saved successfully!

Ooh no, something went wrong!