21.06.2014 Views

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

0 1 2 3 4 5 6<br />

u(t),v(t)<br />

0.01<br />

0.008<br />

0.006<br />

0.004<br />

0.002<br />

0<br />

−0.002<br />

−0.004<br />

−0.006<br />

−0.008<br />

−0.01<br />

u(t)<br />

v(t)/100<br />

RCL−circuit: R=100.000000, L=1.000000, C=0.000001<br />

time t<br />

Fig. 162<br />

R = 100Ω, L = 1H, C = 1µF, U s (t) = 1V sin(t),<br />

u(0) = v(0) = 0 (“switch on”)<br />

ode45 statistics:<br />

17897 successful steps<br />

1090 failed attempts<br />

113923 function evaluations<br />

Maybe the time-dependent right hand side due to the time-harmonic excitation severly affects<br />

ode45? Let us try a constant exciting voltage:<br />

10 M = [0 , 1 ; −beta , −alpha ] ; rhs = @( t , y ) (M∗y − [ 0 ; alpha∗Us( t ) ] ) ;<br />

11 % Set tolerances for MATLAB integrator, see Rem. 11.5.11<br />

12 o p tions = odeset ( ’ r e l t o l ’ , 0 . 1 , ’ a b s t o l ’ ,0.001 , ’ s t a t s ’ , ’ on ’ ) ;<br />

13 y0 = [ 0 ; 0 ] ; [ t , y ] = ode45 ( rhs , tspan , y0 , o p tions ) ;<br />

14<br />

15 % Plot the solution components<br />

16 figure ( ’name ’ , ’ T r a n sient c i r c u i t s i m u l a t i o n ’ ) ;<br />

17 plot ( t , y ( : , 1 ) , ’ r . ’ , t , y ( : , 2 ) /100 , ’m. ’ ) ;<br />

18 xlabel ( ’ { \ b f time t } ’ , ’ f o n t s i z e ’ ,14) ;<br />

19 ylabel ( ’ { \ b f u ( t ) , v ( t ) } ’ , ’ f o n t s i z e ’ ,14) ;<br />

20 t i t l e ( s p r i n t f ( ’RCL−c i r c u i t : R=%f , L=%f , C=%f ’ ,R, L ,C) ) ;<br />

21 legend ( ’ u ( t ) ’ , ’ v ( t ) /100 ’ , ’ l o c a t i o n ’ , ’ northwest ’ ) ;<br />

22<br />

23 p r i n t ( ’−depsc2 ’ , s p r i n t f ( ’ . . / PICTURES/%s . eps ’ , filename ) ) ;<br />

Observation: stepsize control of ode45 (→ Sect. 11.5) enforces extremely small timesteps though<br />

solution almost constant except at t = 0.<br />

Ôº½¿ ½¾º¾<br />

Ôº½ ½¾º¾ ✸<br />

u(t),v(t)<br />

RCL−circuit: R=100.000000, L=1.000000, C=0.000001<br />

2 x 10−3 u(t)<br />

v(t)/100<br />

0<br />

−2<br />

−4<br />

−6<br />

−8<br />

−10<br />

−12<br />

0 1 2 3 4 5 6<br />

time t<br />

Fig. 163<br />

R = 100Ω, L = 1H, C = 1µF, U s (t) = 1V,<br />

u(0) = v(0) = 0 (“switch on”)<br />

ode45 statistics:<br />

17901 successful steps<br />

1210 failed attempts<br />

114667 function evaluations<br />

Code 12.2.2: simulation of linear RLC circuit using ode45<br />

1 function s t i f f c i r c u i t (R, L ,C, Us , tspan , filename )<br />

2 % Transient simulation of simple linear circuit of Ex. refex:stiffcircuit<br />

3 % R,L,C: paramters for circuits elements (compatible units required)<br />

4 % Us: exciting time-dependent voltage U s = U s (t), function handle<br />

5 % zero initial values<br />

6<br />

7 % Coefficient for 2nd-order ODE ü + α ˙u + β = g(t)<br />

8 alpha = 1 / (R∗C) ; beta = 1 / (C∗L ) ;<br />

9 % Conversion to 1st-order ODE y = My + ( 0<br />

g(t))<br />

. Set up right hand side function.<br />

Ôº½ ½¾º¾<br />

Motivated by Ex. 12.2.1 we examine linear homogeneous IVP of the form<br />

( )<br />

0 1<br />

ẏ = y , y(0) = y<br />

−β −α<br />

0 ∈ R 2 . (12.2.1)<br />

} {{ }<br />

=:M<br />

In Ex .12.2.1: β ≫ 1 4 α2 ≫ 1.<br />

[40, Sect. 5.6]: general solution of ẏ = My, M ∈ R 2,2 , by diagonalization of M (if possible):<br />

( )<br />

λ1<br />

MV = M (v 1 ,v 2 ) = (v 1 ,v 2 ) . (12.2.2)<br />

λ2<br />

Idea:<br />

v 1 ,v 2 ∈ R 2 \ {0} ˆ= eigenvectors of M, λ 1 ,λ 2 ˆ= eigenvalues of M, see Def. 5.1.1.<br />

transform ẏ = My into decoupled scalar linear ODEs!<br />

ẏ = My ⇔ V −1 ẏ = V −1 MV(V −1 y)<br />

This yields the general solution of the ODE ẏ = My<br />

z(t):=V −1 y(t)<br />

⇔ ż =<br />

(<br />

λ1<br />

λ2<br />

)<br />

z . (12.2.3)<br />

Ôº½ ½¾º¾<br />

Note: t ↦→ exp(λ i t) is general solution of the ODE ż i = λ i z i .<br />

y(t) = Av 1 exp(λ 1 t) + Bv 2 exp(λ 2 t) , A,B ∈ R . (12.2.4)

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

Saved successfully!

Ooh no, something went wrong!