ODE Systems of LCC Type and Stability

13
%&&$$'() +"# ',-%.,',/ Cover page for assignments Name, personal number, program and email for all students behind this submission : Pierre-Alexandre BEAUFORT, 920104-T093, master in mathematical engineering, [email protected] Hadrien VAN LIERDE, 920909-T058, master in mathematical engineering, [email protected] Course code, course name and program or course set : DN2221, Applied numerical methods - part 1, master of sciences in engineering Teacher: Examiner: Lennart EDSBERG Ashraful KADIR Task name: Deadline: Computer Lab 1 - ODE-systems of LCC-type and stability September 19th 2013 I/We have followed the Code of Honour of the Department of Numerical Analysis when the task was performed. Signature(s): Teacher of the course’s signature: Assessment/Rating: Kungliga Tekniska hogskolan KTH SCI, Lindstedtsvagen 25, 100 44 Stockholm. Tel: 08-790 80 50. Fax: 08-723 17 88. e-mail : [email protected]

description

Computer LAB 1 Supporting Chapter 2 of "Introduction to Computation and Modelling for Differential Equations"

Transcript of ODE Systems of LCC Type and Stability

  • ! !"#$%&&$$'()* +"#*',-%.,',/$011/'+&2#!

    !!!

    !"#$%!!&!#'(#)*+&,-!./0%&%1"#!2*/,.%%3$$*/4!2/.1/#$!!345!*52.,+! !+"#*)--)*$&0(2,&2#*$3.*$&6#*7)83.*(2,,)*',-%.,',/9*!

    !

    !:0#$83(;*80#$,).,*345*1#3/#).*2--2#*80#$3./6,/9!

    !:0#$-2()#29!

    !9!

    !?11/'+&2,$*,).,9!

    !@,-%.,',/$()&0.9!

    !!A)/BC'*5)#*+"-D&*52(2#$83(2E2,*16*)C(2-,',/2,*+"#*F0.2#'$8*G,)-H$*,%#*011/'+&2,*0&+"#&$!

    !!!!F).,&248,',/=)#>!

    !

    !!!!!

    :0#$-2()#2,$*$'/,)&0#9** I2(".,',/B72&H/9!!!!!!!

    Kungliga Tekniska hgskolan !

    KTH SCI, Lindstedtsvgen 25, 100 44 Stockholm. Tel: 08-790 80 50. Fax: 08-723 17 88. E-post: [email protected]

    Cover page for assignments

    Name, personal number, program and email for all students behind this submission :

    Pierre-Alexandre BEAUFORT, 920104-T093, master in mathematical engineering, [email protected] VAN LIERDE, 920909-T058, master in mathematical engineering, [email protected]

    Course code, course name and program or course set :

    DN2221, Applied numerical methods - part 1, master of sciences in engineering

    Teacher: Examiner:Lennart EDSBERG Ashraful KADIRTask name: Deadline:Computer Lab 1 - ODE-systems of LCC-type and stability September 19th 2013

    I/We have followed the Code of Honour of the Department of Numerical Analysiswhen the task was performed.

    Signature(s):

    Teacher of thecourses signature:

    Assessment/Rating:

    Kungliga Tekniska hogskolanKTH SCI, Lindstedtsvagen 25, 100 44 Stockholm. Tel: 08-790 80 50. Fax: 08-723 17 88.

    e-mail : [email protected]

  • Contents

    1 Solution of ODE-systems with constant coefficients . . . . . . . . . . . . . . . . 12 Stability of ODE-systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2.1 Stability of the solutions of an ODE-system of LCC-type . . . . . . . . . 32.2 Stability of critical points of a nonlinear ODE-system . . . . . . . . . . . 7

    A Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8A.1 Marginal and asymptotic stability . . . . . . . . . . . . . . . . . . . . . . 8A.2 DN2221_lab1_Part1.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8A.3 DN2221_lab1_Part2a1.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 9A.4 DN2221_lab1_Part2a2.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 10A.5 DN2221_lab1_Part2b.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    0

  • 1 Solution of ODE-systems with constant coefficientsIn this section, we analyze a simple electric circuit with following components in series : a voltage source of size E = 10[V ] a resistance R = [0.1 1 10 100]T [] an inductance L = 0.1[H] a capacitance C = 0.1[F ]We are going to observe the behaviour of the circuit with different values of R.

    First, for t < 0 the circuit is open. Then, at t = 0 it is closed and thus the current i(t) = q(t)starts to go through the circuit according to the following differential equation :

    Lq +Rq + 1Cq = E

    with initial contions : u0 {q(t = 0) = 0i(t = 0) = 0

    We can rewrite this scalar ODE as a system of first ODEs :

    dudt

    = Au+

    dq

    dt= i

    di

    dt= 1

    L

    ((Ri+ q

    C) + E

    )

    with u = [q i]T , A =(

    0 11LC

    RL

    )and = [0 E

    L]T .

    Therefore, we know thatu(t) = uH(t) + up(t)

    where uH is the solution of the corresponding homogeneous ODEs-system and up is a particularsolution of the nonhomogeneous ODEs-system.Straightaway, we write :

    uH(t) = exp(At) dwhere d will be determined in regard with the initial conditions applied to u.A particular solution of u is :

    up(t) = A1 1Now, we have to determine d in regard with the initial conditions :

    u0 =[

    00

    ]= I d+

    [EC0

    ]= d =

    [ EC0

    ]

    Finally, we obtain :u(t) = exp(At)dA1

    The MatLab function that computes and displays solution of ODE is available in appendix A.2.Figure 1 illustrates solutions for different values of R.

    1. A1 =( RC LC

    1 0

    )

    1

  • 0 5 10 15 200

    0.5

    1

    1.5

    2

    2.5Charge for R = 0.1ohm

    Time [s]

    Char

    ge [C

    ]

    0 5 10 15 2010

    8

    6

    4

    2

    0

    2

    4

    6

    8Current for R = 0.1ohm

    Time [s]

    Curre

    nt [A

    ]

    0 5 10 15 200.8

    1

    1.2

    1.4

    1.6

    1.8

    2

    2.2Charge for R = 1ohm

    Time [s]

    Char

    ge [C

    ]

    0 5 10 15 206

    5

    4

    3

    2

    1

    0

    1Current for R = 1ohm

    Time [s]

    Curre

    nt [A

    ]

    0 5 10 15 201

    1.2

    1.4

    1.6

    1.8

    2

    2.2Charge for R = 10ohm

    Time [s]

    Char

    ge [C

    ]

    0 5 10 15 201

    0.9

    0.8

    0.7

    0.6

    0.5

    0.4

    0.3

    0.2

    0.1

    0Current for R = 10ohm

    Time [s]

    Curre

    nt [A

    ]

    0 5 10 15 201.1

    1.2

    1.3

    1.4

    1.5

    1.6

    1.7

    1.8

    1.9

    2

    2.1Charge for R = 100ohm

    Time [s]

    Char

    ge [C

    ]

    0 5 10 15 200.1

    0.09

    0.08

    0.07

    0.06

    0.05

    0.04

    0.03

    0.02

    0.01

    0Current for R = 100ohm

    Time [s]

    Curre

    nt [A

    ]

    Figure 1: Plot of solutions : first row, charge q[C] in function of time t[s] and second row,current i[A] in function of time t[s]. Solutions are displayed in respect for R = [0.1 1 10 100]. Here, t = linspace(0,20,500).

    2

  • 2 Stability of ODE-systems2.1 Stability of the solutions of an ODE-system of LCC-typeLets consider the following initial value problem:

    y + 3y + 2y +Ky = 0, y(0) = 1, y(0) = 1, y(0) = 1. (1)

    We rewrite this equation as the following system of first order equations:y1 = y2 y1(0) = 1y2 = y3 y2(0) = 1y3 = 3y3 2y2 Ky1 y3(0) = 1

    (2)

    We can also write this system in a vector form introducing the following notation:

    A =

    0 1 00 0 1K 2 3

    (3)We obtain the following system in a vector form:

    u = A(K)u, u(0) = (1, 1, 1)T (4)

    The solution of this system is given by

    u(t) = exp(At)u(0) (5)

    This solution can be computed by using the expm function of MATLAB. We obtain the graphgiven by the figure 2 for K = 0, 1, 4, 8 (we only give the graph of y1):

    We chose the number of time intervals for the discretization in order to be able to observe theoscillations of the solution 2. We chose the total time of observation to see if the equations givea stable result or not 3. Looking at the figure 2, it seems that the solutions of the system arestable for K = 0, 1 and 4 and unstable for K = 8. The MatLab code used to compute thesegraphs is given in appendix (see A.3).

    Lets analyze the stability of the solutions of the system. To do this for a specific value of K,we have to check the signs of all eigenvalues of the corresponding matrix A. The graph 3 givesthe continuous curve followed by the eigenvalues of A when K increases from 0 to 10.

    To analyze this graph, lets remind the criterion of stability of a system of linear differentialequations with constant coefficients 4.

    2. To select the best length of interval, we compute the eigenvalues of the matrix A for each value of K.The imaginary part of each eigenvalue corresponds to a frequency of oscillation of one term of the solution(actually, the frequency is given by the imaginary part divided by 2pi). The biggest imaginary part in absolutevalue of all eigenvalues allows us to compute the minimum length of interval we need. In this case, the curvecorresponding to K = 8 oscillates with the highest frequency. Thus, we choose a time interval allowing torepresent the oscillations of this curve, 1 second. But we chose 0.1 second to obtain a smoother curve.

    3. This observation is of course arbitrary. We will give later an accurate way to analyze the stability of thesystem.

    4. The following criterion is given by the documents of the course given at the Universit catholique deLouvain: FSAB1106, Signaux et Systmes, VANDENDORP (L.) and WERTZ (V.)

    3

  • 0 50 1002

    2.5

    3

    3.5

    time(s)

    y(t)

    0

    0 50 1001

    0

    1

    2

    3

    time(s)

    y(t)

    1

    0 50 1002

    1

    0

    1

    2

    time(s)

    y(t)

    4

    0 50 1005000

    0

    5000

    10000

    time(s)

    y(t)

    8

    Figure 2: Plot of solutions for four values of K given above each graph. Here t =linspace(0,100,100).The MatLab code produces this figure is available in the appendix A.3.

    Proposition 1Given a matrix A Rnn with eigenvalues {i|1 i n} and a linear system dudt = Au, if R(i) < 0 i, then the solution of the system is stable (asymptotically) 5, if R(i) 0 i and R(i) = 0 for some i then, if we verify the following condition, thesolution is stable (marginally): when R(i) = 0, the algebraic multiplicity of i as a rootof the characteristic polynomial is equal to the dimension of the space spanned by theeigen vectors associated to i,

    4

  • 3.5 3 2.5 2 1.5 1 0.5 0 0.52

    1.5

    1

    0.5

    0

    0.5

    1

    1.5

    2

    Real Part

    Imag

    inar

    y Pa

    rt

    Figure 3: Root locus for 500 values of K between 0 and 10. The red point corresponds toK = 0, the black point to K = 6 and the green point to K = 10. The MatLab code producesthis figure is available in the appendix A.4.

    in all other cases, the solution is unstable

    In other words, if for a given value of K, one eigen value of A is of zero real part, we may checkif the corresponding matrix is diagonalizable to ensure the stability of the solution. We canfind numerically for which value of K, the matrix A has one (or more) eigenvalue of positivereal part. As we can see on the graph 3, A starts to have two eigenvalues of non-negative realpart for some value of K between 0 and 10 (denoted by the black point on the graph 3). Wefind numerically that this value is 6 (after testing for 100000 values of K between 0 and 10,we obtain 6.0001). The MatLab code used to compute this result is given in appendix (see A.4).

    How can we be sure that K = 6 is the limit value of K to keep a stable system? We can useRouth Criterion on the characteristic polynomial: y3 + 3y2 + 2y+K. The Routh table is givenby:

    5

  • 1 23 K

    6K3 0

    K 0

    All the roots of the characteristic polynomial have a strictly negative real part if and only ifthe elements of the first row of the table are all nonzero and have all the same sign. This istrue if 0 < K < 6. What about K = 0 and K = 6? We can check that in these two cases, thematrix has three distinct eigenvalues, it is thus diagonalizable and the solutions for these twovalues of K are stable (marginally).

    To summarize these results: if K = 0 and K = 6, the real parts of all eigenvalues are lower or equal to zero and at leastone has zero real part but, as the matrix is diagonalizable, the solution is stable (marginally)

    if 0 < K < 6, according to the Routh table, the real parts of all eigenvalues of A are strictlynegative, the solution is thus stable (asymptotically)

    if 6 < K 10, as we can see on the graph 3 at least one eigen value has a strictly positivereal part and the solution is unstable.

    6

  • 2.2 Stability of critical points of a nonlinear ODE-systemHere, we analyze the critical points of a non linear ODE-system. A critical point u of a non-linear ODE-system du

    dt= f(u; t) is a point such that f(u; t) = 0. Our study is focused on

    the non-linear ODE-system :x = 5x+ 4y xzy = x+ 4y yzz = x2 + y2 89

    with Jf =

    5 z 4 x1 4 z y2x 2y 0

    where Jf is the jacobian of f .

    We compute the critical points by using Newtons method : Jf (ui) ui = f(ui)ui+1 = ui + uiwhere Jf (ui), f(ui) and ui are known.

    Newtons method is an iterative method to compute a solution of a nonlinear system of equa-tions. Here, we want to compute solutions with 5 pertinent decimals (about its coordinates). Weknow there are 4 critical points and they are near (8;5; 2), (8; 5; 2), (9; 3; 7) and (9;3; 7).These points are our initial points for Newtons method. Besides, we can analyze the stabilityof a critical point from its jacobian. A critical point is asymptotically stable if and only if itsjacobian is negative definite 6.

    The MatLab function computes critical point is available in appendix A.5. We obtain thefollowing critical points :

    (x; y; z) Jf Stability

    (7.94457;5.08761; 2.43844) 2.56155 4 7.944571 1.56155 5.08761

    15.88914 10.17522 0

    1015 13.34166i

    1015 + 13.34166i4.1231

    Unstable

    (7.94457; 5.08761; 2.43844) 2.56155 4 7.944571 1.56155 5.0876115.88914 10.17522 0

    1015 13.34166i

    1015 + 13.34166i4.1231

    Unstable

    (8.78805; 3.43075; 6.56155)

    1.56155 4 8.788051 2.56155 3.4307517.57611 6.8615 0

    0 13.34166i0.0... 13.34166i4.1231

    Stable

    (8.78805;3.43075; 6.56155)1.56155 4 8.788051 2.56155 3.43075

    17.57611 6.8615 0

    0 13.34166i0.0... 13.34166i4.1231

    Stable

    We note that the two last critical points have both a jacobian with 2 eigenvalues whose realparts are near zero. But since MatLab returns 0.0..., we concluded that these two points areasymptotically stable. Nevertheless, if we consider these eigenvalues have a zero real part, thesepoints are marginally stable as their associated jacobian are diagonalizable.

    6. For further details see proposition 1

    7

  • A AppendixA.1 Marginal and asymptotic stabilityIn the section 1, we introduced the terms "asymptotically" and "marginally" stable. Here arethe definitions of these two concept 7

    1. Marginal stabilityGiven Rn an open set, f : Rn a vector field and t0 R, then the point u0 ismarginally stable (in the sense of Lyapunov) if

    > 0, > 0 such that ,x B(u0, ),there exists a differentiable function u : [t0,[ Rn such that t t0,u(t) B(u0, )u(t) = f(u(t))u(t0) = x

    (6)

    2. Asymptotic stabilityGiven Rn an open set, f : Rn a vector field and t0 R, then the point u0 isasymptotically stable if it is marginally stable there exists > 0 such that x B(u0, ),if u is a solution ofu(t) = f(u(t)) t [t0,[u(t0) = x (7)then lim

    tu(t) = u0

    One can show that if a point u0 is stable, then it has to be a critical point what meansthat f(u0) = 0. In the case of an homogeneous system of differential equation with constantcoefficients of the type u = Au, if A is nonsingular, the unique critical point is zero. In thatspecial case, we say that we analyze the "stability of the solution" when the initial condition isnonzero. This means we actually analyze the stability of the point zero.

    A.2 DN2221_lab1_Part1.m

    12 % [DN2221 - Lab1]3 % Part 1, Beaufort & Van Lierde4 %%%%5 % DN2221_lab1_Part1(t) is a function computes analytical solution of ODE6 % equation Lq + Rq +1/C q = E, for some points contained in the vector t7 % Solution is computed for :8 % *E = 10; %[V]9 % *R = [0.1 1 10 100]; %[ohm]10 % *L = 0.1; %[H]11 % *C = 0.1; %[F]12 % Solution is displayed for different values of R ;13 % besides , it displays i = q14 %%%%15 f unc t i on u = DN2221_lab1_Part1(t)

    7. VAN SCHAFTINGEN (J.) professor at the Universit Catholique de Louvain, course LMAT1223,Equations diffrentielles ordinaires, Universit Catholique de Louvain, 2012, pp.75-77 (syllabus).

    8

  • 1617 E = 10; %[V]18 R = [0.1 1 10 100]; %[ohm]19 L = 0.1; %[H]20 C = 0.1; %[F]2122 sR = l ength (R);23 lT = l ength (t);2425 f o r i = 1 : sR2627 A = [0 1 ; -1/(L*C) -R(i)/L];28 invA = [-R(i)*C -L*C ; 1 0];29 Epsilon = [0 E/L];30 u = z e ro s (2,lT);31 up = invA*Epsilon;32 u0 = -up;33 % analytical solution of ODE34 % du/dt = A*u + Epsilon35 % u(t=0) = u036 % is :3738 % - homogenous39 f o r j = 1 : lT40 u(:,j) = expm(A*t(j))*u0;41 end42 % - particular43 u = u - up*ones(1,lT);4445 %display46 subplot (2,sR,i)47 p lo t (t,u(1,:) );48 t i t l e ([Charge for R = , num2str(R(i)), ohm]);49 g r id on50 x l ab e l (Time [s])51 y l ab e l (Charge [C]);5253 %%%%%%5455 subplot (2,sR,i+sR)56 p lo t (t,u(2,:) )57 t i t l e ([Current for R = , num2str(R(i)),ohm]);58 g r id on59 x l ab e l (Time [s])60 y l ab e l (Current [A]);6162 end63 end

    A.3 DN2221_lab1_Part2a1.m

    1 %% 2.a : Stability of a system - solution for different values of K2 % This program computes the solution of the system described in the main3 % document for four different values of K (0, 1, 4 and 8). The solutions4 % are computed using the function expm. The total time of observation is5 % 100s and the length of each time interval is 0.1s.67 c l o s e a l l8 k=[0 1 4 8];9 y0 =[1;1;1];10 t= l i n s p a c e (1 ,100 ,1000);11 f o r i=1: l ength (k)12 K=k(i);13 A=[0 1 0;0 0 1;-K -2 -3];14 y= z e ro s (3, l ength (t));15 f o r j=1: l ength (t)16 y(:,j)=expm(A*t(j))*y0;

    9

  • 17 end18 subplot (2,2,i);19 p lo t (t,y(1,:));20 x l ab e l (time(s))21 y l ab e l (y(t))22 t i t l e (k(i))23 end

    A.4 DN2221_lab1_Part2a2.m

    1 %% 2.a : Stability of a system - Root Locus2 % This program computes the eigen values of the matrix A for n different3 % values of K between 0 and 10. It displays all the eigen values in the4 % complex plane and it finds the limit value of K to obtain a stable5 % solution.67 n=500;8 c l o s e a l l9 K= l i n s p a c e (0,10,n);10 R= z e ro s (1,3* l ength (K));11 indice =0;12 found =0;1314 f o r k=1: l ength (K);15 A=[0 1 0;0 0 1;-K(k) -2 -3];16 r= e i g (A);17 f o r j=1:318 i f abs( imag(r(j))) =0 && found ==0 && k~=122 found =1;23 indice=k;24 end25 end26 R(3*(k-1) +1:3*(k-1)+3)=r;27 end2829 di sp (The limit value of K is)30 K(indice)31 f i g u r e32 p lo t (R(1:3),ro)33 hold on34 p lo t (R(3* l ength (K) -2:3* l ength (K)),go)35 p lo t (R(3*( indice -1) +1:3*( indice -1) +3),ko)36 p lo t (R(4:3* l ength (K) -3),.)37 g r id on38 x l ab e l (Real Part)39 y l ab e l (Imaginary Part)

    A.5 DN2221_lab1_Part2b.m

    1234 %5 % DN2221 - lab16 % Part2b , Beaufort & Van Lierde7 %8 %%%%9 % DN2221_lab1_Part2b(u0) computes critical point of the non -linear ODE , by10 % using Newton s method.11 % The function returns critical point near u0 and the associated Jacobian

    10

  • 12 % in order to analyse the stability of critical point.13 %14 %%%%1516 f unc t i on [Ucrit ,Jf] = DN2221_lab1_Part2b(u0)171819 u = z e ro s (2,3);2021 du = -J(u0)\f(u0);22 Unew = u0 + du;23 Uold = Unew + 1;24 N = 0;2526 whi le abs(Unew (1)-Uold (1)) >= 1e-5 && abs(Unew (2)-Uold (2)) >= 1e-5 && abs(Unew (3)-Uold (3)) >=

    1e-5 && N