Anda di halaman 1dari 17

Applied Numerical Methods KTH DN2221 Computer Lab 1 ODE-Systems of LCC-type and Stability

Sebastian Arnoldt 12-2012

KTH - DN2221 - Computer Lab 1

Contents

1 Part 1 - Solution of ODE-systems with constant coecients 2 2 Part 2 - Stability of ODE-systems 4 3 Appendix
3.1 3.2 3.3 3.4

2.1 Part 2a - Stability of the solutions of an ODE-system of LCCtype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.2 Part 2b - Stability of critical points of a non-linear ODE-system 7 A1 - MATLAB code for part 1 . . . . . . . . . . . A.2a1 - MATLAB code for part 2a - estimating K A.2a1 - MATLAB code for part 2a - Root Locus . A.2b - MATLAB code for part 2b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 . 11 . 12 . 14

4 Bibliography

16

KTH - DN2221 - Computer Lab 1

1 Part 1 - Solution of ODE-systems with constant coecients


A resistance R, an inductance L and a capacitance C are coupled in series. Before a voltage source of size E is connected at the time t = 0, the circuit is at rest. Following [1], this electric ciruit can be described by the dierential equation
1 q=E (1) C , with the initial values q (0) = 0 and q (0) = 0. Here, q is the electric charge and q = i is the electric current. Eq.(1) can be rewritten as a system of rst order ODEs. With q = i, we have Lq + Rq + d = dt

q i

0 C1 L

1 R L

q i

0
E L

Au + g

, whose analytic solution is described by the Duhamel formula given as eq.(2.25) in [1]. Since is independent of t and (0) = (0, 0)T in the given system, the Duhamel formula can be simplied to give the solution vector (t) = 1 (eAt Id) . (t) is calculated in MATLAB [2] using the MATLAB code appended in Appendix A1 (sec 3.1). For the calculation, the parameters are set to the values E = 10, L = C = 0.1 and R is varied as R = 1, 10, 100, 1000, 10000. In q.1 below both components of the solution vector (t) are plotted as a function of time. From the upper left to the lower right, the parameter R increases by a factor of 10. The system exhibits the expected behaviour. Since E is a constant voltage source - as opposed to a time dependent voltage source - the electric current in the circuit depends solely on the size of the resistance R and practically vanishes for R = 10000.

g u

KTH - DN2221 - Computer Lab 1

Figure 1: Plot of the components of the solution vector of eq. 1 at various values for the resistance R.

KTH - DN2221 - Computer Lab 1

2 Part 2 - Stability of ODE-systems


2.1 Part 2a - Stability of the solutions of an ODE-system of LCC-type

In this part of the lab, we investigate how the solution of the dierential equation
y + 3y + 2y + Ky = 0

(2)

with the initial conditions y (0) = 1, y (0) = 1 and y (0) = 1, behaves as the value of K is varied over K = 0, 1, 4, 8. As a rst step, we rewrite the third order ODE into a system of rst order ODEs. With the abbreviations r = y and s = r we get the system:
3 2 K s s 0 0 r = A u r = 1 0 1 0 y y

. Following [1], the solution vector of this system can be found using u(t) = eAt u0 , where u0 is given by the initial conditions as u0 = (1, 1, 1)T . The plots of the components s,r and y of the solution vector (t) at various values for the parameter K are shown in g.2 below. The MATLAB code that produces these plots is appended in Appendix A.2a1 (sec 3.2). From g. 2 below we estimate that the system becomes unstable in the region 4 < K < 8. Next, we plot the root locus of eq.(2), shown in g.3 below. The MATLAB code for the plot is appended in Appendix A.2a2 (sec 3.3)). Decreasing the step size of the parameter K in the code, we nd that the smallest value of K that gives an unstable system is K = 6.0000.

u(t)

KTH - DN2221 - Computer Lab 1

Figure 2: Plots of the components s,r and y of the solution vector (t) at various values for the parameter K

KTH - DN2221 - Computer Lab 1

Figure 3: Plot of the root locus of eq.(2) for 0 K 10

KTH - DN2221 - Computer Lab 1


2.2

Part 2b - Stability of critical points of a non-linear ODE-system

In this part of Lab 1 we compute the critical points of the non-linear ODESystem given in the lab assignment or on page 218 in [1]. To do this, we u = 0 by means of Newton's Method described solve the equation f (u) = d dt in Appendix A.1 in [1]. The central element of the solution process is the coding of the recursive formula
u(i+1) = u(i) J (u(i) )1 f (u(i) )

where is the solution vector, J the Jacobian of the ODE-system. Eq. 3 is given in [1] in Appendix 1 as eq. (A.7). Using the start points given in the lab assignment, we use the code given in Appendix A.2b (sec. 3.4) to rst calculate the critical points. We then plug the calculated critical points into the Jacobian and nd its eigenvalues for each of the four points. The calculated critical points are (7.95037, -5.07940, 2.44169), (-7.94457, 5.08761, 2.43845), (8.81439, 3.39015, 6.54798) and (8.81439, -3.39015, 6.54798). For each of them, the corresponding Jacobian has three eigenvalues. These eigenvalues are also calculated in the MATLAB code in Appendix A.2b (sec. 3.4) and plotted in the complex plane in g.4 below. Here we see, that the rst two points - in the upper half of g. 4 are unstable. The last two points - in the lower half of g. 4 - however, are stable stationary points of the ODE-system.

(3)

KTH - DN2221 - Computer Lab 1

Figure 4: Eigenvalues of the Jacobian J at calculated critical points of the given ODE system

KTH - DN2221 - Computer Lab 1

3 Appendix
3.1 A1 - MATLAB code for part 1

E = 1 0 ; L = 0 . 1 ; C = 0 . 1 ; preR = [ 1 , 10 , 100 , 1000 , 1 0 0 0 0 ] ; %s e t parameters for n = 1:5 R = preR ( n ) %loop through parameter R

S = 1/(C * L) ; T = R/L ; U = E/L ; %d e f i n e s h o r t c u t s A = [ 0 1; S T] ; %d e f i n e Matrix A g = [ 0 U ] '; % d e f i n e column v e c t o r g % s i n c e i n i t i a l v a l u e s f o r q and q ' a re 0 , only need to c a l c u l a t e second % term i n forumla ( 2 . 2 6 ) from book for k = 1:500 t = ( k 1) * 0 . 0 1 ; %s e t time r e s o l u t i o n to 0 . 1 s e c per i t e r a t i o n , s t a r t i n g at t = 0 time ( ( k ) , : ) = t ; %s t o r e time i n v e c t o r %u_t = inv (A) * (expm(A* t )eye ( 2 ) ) * g ; % c a l c u l a t e s o l u t i o n u_t f o r each value o f t u_t = A\ ( ( expm(A* t )eye ( 2 ) ) * g ) ;

KTH - DN2221 - Computer Lab 1 mat ( ( k ) , : ) = u_t ; r e s u l t i n a matrix end subplot (3 ,2 ,n) ; p l o t ( time , mat ) t i t l e ( [ 'R = ' , num2str (R) ] ) x l a b e l ( ' time / t ' ) ylabel ( ' u( t ) / arbitrary units ' ) ; mat end ;

10 %s t o r e

KTH - DN2221 - Computer Lab 1


3.2

11

A.2a1 - MATLAB code for part 2a - estimating K

preK = [ 0 , 1 , 4 , 8 ] ; %d e f i n e parameter preK h = 0 . 0 1 ; N = 5000; %s e t s t e p s i z e and number f o r time c a l c u l a t i o n s u0 = [ 1 1 1 ] ' ; %d e f i n e v e c t o r u0 for n = 1 : 4 %loop through preK to define K K = preK ( n ) ; A = [ 3 2 K; 1 0 0 ; 0 1 0 ] ; %d e f i n e matrix A f o r k = 1 :N t = h * ( k 1) ; time ( k , : ) = t ; u = expm(A* t ) * u0 ; mat ( k , : ) = u ;

end subplot (2 ,2 ,n) ; p l o t ( time , mat ) t i t l e ( [ 'K = ' , num2str (K) ] ) x l a b e l ( ' time / t ' ) y l a b e l ( ' components o f s o u l t i o n v e c t o r u ( t ) ' ) ; end

KTH - DN2221 - Computer Lab 1


3.3 A.2a1 - MATLAB code for part 2a - Root Locus

12

K = 0; h = 0.001; k=1; w h i l e ( K <= 10) A = [ 3 2 K; 1 0 0 ; 0 1 0 ] ; Eigenvalues of A vec = e i g (A) ' ; e i g e n v a l u e s ( k , : ) = vec ; dummy = [ e i g (A) ' K ] ; mat ( k , : ) = dummy; K = K + h; k = k + 1; %c a l c u l a t e

end

Re1 = r e a l ( e i g e n v a l u e s ( : , 1 ) ) ; Im1 = imag ( e i g e n v a l u e s ( : , 1 ) ) ; Re2 = r e a l ( e i g e n v a l u e s ( : , 2 ) ) ; Im2 = imag ( e i g e n v a l u e s ( : , 2 ) ) ; Re3 = r e a l ( e i g e n v a l u e s ( : , 3 ) ) ; Im3 = imag ( e i g e n v a l u e s ( : , 3 ) ) ;

p l o t ( Re1 , Im1 , Re2 , Im2 , Re3 , Im3 )

KTH - DN2221 - Computer Lab 1 t i t l e ( ' Root Locus ' ) x l a b e l ( ' Re( z ) ' ) y l a b e l ( ' Im( z ) ' ) ; %f i l t e r from c a l c u l a t i o n s s m a l l e s t value o f K that g i v e s an u n s t a b l e system

13

n=1; w h i l e ( r e a l ( mat ( n , 3 ) ) < 0 | | r e a l ( mat ( n , 2 ) ) < 0 | | r e a l ( mat ( n , 3 ) ) < 0) n = n+1; end d i s p ( [ ' s m a l l e s value o f K that g i v e s u n s t a b l e system i s : ' , num2str ( mat ( n 1 ,4) ) ] )

KTH - DN2221 - Computer Lab 1


3.4 A.2b - MATLAB code for part 2b

14

Main MATLAB script used in part 2b p r e s e t s = [ 8 5 2 ; 8 5 2 ; 9 3 7 ; 9 3 7 ] ; format long ; for k = 1:4 u_i = p r e s e t s ( k , : ) ; count =1; dh=1; condition = 0.00001;

w h i l e ( ( dh > c o n d i t i o n ) ) % & ( dh < 10^5) ) count = count +1; J_h = Jacobian ( u_i ( 1 ) , u_i ( 2 ) , u_i ( 3 ) ) ; f_h= f ( u_i ( 1 ) , u_i ( 2 ) , u_i ( 3 ) ) ; dh = h (J_h , f_h ) ; u_new = dh + u_i ' ; u_i = u_new ' ; end r e s u l t ( k , : ) = u_new ; k = k + 1; end

for n = 1:4 A=Jacobian ( r e s u l t ( n , 1 ) , r e s u l t ( n , 2 ) , r e s u l t ( n , 3 ) ) ; e i g e n = e i g (A) ;

KTH - DN2221 - Computer Lab 1

15

Re = r e a l ( e i g e n ) ; Im = imag ( e i g e n ) ; subplot (2 ,2 ,n) p l o t (Re ( 1 ) ,Im ( 1 ) , Re ( 2 ) ,Im ( 2 ) ,Re ( 3 ) ,Im ( 3 ) , ' Marker ' , ' x ' , ' MarkerSize ' , 1 2 ) t i t l e ( [ ' S t a b i l i t y at Point [ ' , num2str ( r e s u l t ( n , : ) ) , '] ']) x l a b e l ( ' Re( z ) ' ) y l a b e l ( ' Im( z ) ' ) ; end

d i s p ( ' The c r i t i c a l p o i n t s are at : ' ) ; result Additional functions used in function les in part 2b f u n c t i o n [ r e s u l t ] = f ( u1 , u2 , u3 ) %f u n c t i o n f o f LAB1 r e s u l t = [ (5 * u1 + 4 * u2 u1 * u3 ) ; ( u1 + 4 * u2 u2 * u3 ) ; ( u1^2 + u2^2 89) ] ; end function [ x ] = h(J , f ) %c o r r e c t i o n term h f o r the Newton Method used i n part 2 b x = linsolve (J , f ) ; end f u n c t i o n [ r e s u l t ] = Jacobian ( u1 , u2 , u3 ) %Jacobian used i n part 2b r e s u l t = [(5 u3 ) 4 ( 1 * u1 ) ; 1 (4 u3 ) ( 1 * u2 ) ; 2 * u1 2 * u2 0]; end

KTH - DN2221 - Computer Lab 1

16

4 Bibliography References
[1] L. Edsberg, 2008. [2] MATLAB, 2012. MathWorks Inc.
Introduction to Computation and Modelling for Differential Equations.

1st edition. New Jersey: John Wiley & Sons. Natick, MA: The

MATLAB R2012a (7.14.0.739).

Anda mungkin juga menyukai