You are on page 1of 13

!"#$%&&$$'() +"# ',-%.

,',/$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

<#),$8)#2 =3. ),,), %, 80#$-2()#2,>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: elevexp@math.kth.se
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, beaufort@kth.se
Hadrien VAN LIERDE, 920909-T058, master in mathematical engineering, hvl@kth.se
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
courses 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 : elevexp@math.kth.se
Contents
1 Solution of ODE-systems with constant coecients . . . . . . . . . . . . . . . . 1
2 Stability of ODE-systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Stability of the solutions of an ODE-system of LCC-type . . . . . . . . . 3
2.2 Stability of critical points of a nonlinear ODE-system . . . . . . . . . . . 7
A Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
A.1 Marginal and asymptotic stability . . . . . . . . . . . . . . . . . . . . . . 8
A.2 DN2221_lab1_Part1.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
A.3 DN2221_lab1_Part2a1.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
A.4 DN2221_lab1_Part2a2.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
A.5 DN2221_lab1_Part2b.m . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
0
1 Solution of ODE-systems with constant coecients
In 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 dierent 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 dierential equation :
L q +R q +
1
C
q = E
with initial contions : u
0

_
q(t = 0) = 0
i(t = 0) = 0
We can rewrite this scalar ODE as a system of rst ODEs :
du
dt
= Au +
_

_
dq
dt
= i
di
dt
=
1
L
_
(Ri +
q
C
) +E
_
with u = [q i]
T
, A =
_
0 1
1
LC
R
L
_
and = [0
E
L
]
T
.
Therefore, we know that
u(t) = u
H
(t) +u
p
(t)
where u
H
is the solution of the corresponding homogeneous ODEs-system and u
p
is a particular
solution of the nonhomogeneous ODEs-system.
Straightaway, we write :
u
H
(t) = exp(At) d
where d will be determined in regard with the initial conditions applied to u.
A particular solution of u is :
u
p
(t) = A
1

1
Now, we have to determine d in regard with the initial conditions :
u
0
=
_
0
0
_
= I d +
_
EC
0
_
= d =
_
EC
0
_
Finally, we obtain :
u(t) = exp(At)d A
1

The MatLab function that computes and displays solution of ODE is available in appendix A.2.
Figure 1 illustrates solutions for dierent values of R.
1. A
1
=
_
RC LC
1 0
_
1
0 5 10 15 20
0
0.5
1
1.5
2
2.5
Charge for R = 0.1ohm
Time [s]
C
h
a
r
g
e

[
C
]
0 5 10 15 20
10
8
6
4
2
0
2
4
6
8
Current for R = 0.1ohm
Time [s]
C
u
r
r
e
n
t

[
A
]
0 5 10 15 20
0.8
1
1.2
1.4
1.6
1.8
2
2.2
Charge for R = 1ohm
Time [s]
C
h
a
r
g
e

[
C
]
0 5 10 15 20
6
5
4
3
2
1
0
1
Current for R = 1ohm
Time [s]
C
u
r
r
e
n
t

[
A
]
0 5 10 15 20
1
1.2
1.4
1.6
1.8
2
2.2
Charge for R = 10ohm
Time [s]
C
h
a
r
g
e

[
C
]
0 5 10 15 20
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
Current for R = 10ohm
Time [s]
C
u
r
r
e
n
t

[
A
]
0 5 10 15 20
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2
2.1
Charge for R = 100ohm
Time [s]
C
h
a
r
g
e

[
C
]
0 5 10 15 20
0.1
0.09
0.08
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
Current for R = 100ohm
Time [s]
C
u
r
r
e
n
t

[
A
]
Figure 1: Plot of solutions : rst 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-systems
2.1 Stability of the solutions of an ODE-system of LCC-type
Lets 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 rst order equations:
_

_
y

1
= y
2
y
1
(0) = 1
y

2
= y
3
y
2
(0) = 1
y

3
= 3y
3
2y
2
Ky
1
y
3
(0) = 1
(2)
We can also write this system in a vector form introducing the following notation:
A =
_

_
0 1 0
0 0 1
K 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 graph
given by the gure 2 for K = 0, 1, 4, 8 (we only give the graph of y
1
):
We chose the number of time intervals for the discretization in order to be able to observe the
oscillations of the solution
2
. We chose the total time of observation to see if the equations give
a stable result or not
3
. Looking at the gure 2, it seems that the solutions of the system are
stable for K = 0, 1 and 4 and unstable for K = 8. The MatLab code used to compute these
graphs is given in appendix (see A.3).
Lets analyze the stability of the solutions of the system. To do this for a specic value of K,
we have to check the signs of all eigenvalues of the corresponding matrix A. The graph 3 gives
the 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 dierential
equations with constant coecients
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 2). The biggest imaginary part in absolute
value of all eigenvalues allows us to compute the minimum length of interval we need. In this case, the curve
corresponding to K = 8 oscillates with the highest frequency. Thus, we choose a time interval allowing to
represent 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 the
system.
4. The following criterion is given by the documents of the course given at the Universit catholique de
Louvain: FSAB1106, Signaux et Systmes, VANDENDORP (L.) and WERTZ (V.)
3
0 50 100
2
2.5
3
3.5
time(s)
y
(
t
)
0
0 50 100
1
0
1
2
3
time(s)
y
(
t
)
1
0 50 100
2
1
0
1
2
time(s)
y
(
t
)
4
0 50 100
5000
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 gure is available in the appendix A.3.
Proposition 1
Given a matrix A R
nn
with eigenvalues {
i
|1 i n} and a linear system
du
dt
= 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, the
solution is stable (marginally): when R(
i
) = 0, the algebraic multiplicity of
i
as a root
of the characteristic polynomial is equal to the dimension of the space spanned by the
eigen vectors associated to
i
,
4
3.5 3 2.5 2 1.5 1 0.5 0 0.5
2
1.5
1
0.5
0
0.5
1
1.5
2
Real Part
I
m
a
g
i
n
a
r
y

P
a
r
t
Figure 3: Root locus for 500 values of K between 0 and 10. The red point corresponds to
K = 0, the black point to K = 6 and the green point to K = 10. The MatLab code produces
this gure 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 check
if the corresponding matrix is diagonalizable to ensure the stability of the solution. We can
nd numerically for which value of K, the matrix A has one (or more) eigenvalue of positive
real part. As we can see on the graph 3, A starts to have two eigenvalues of non-negative real
part for some value of K between 0 and 10 (denoted by the black point on the graph 3). We
nd 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 use
Routh Criterion on the characteristic polynomial: y
3
+3y
2
+2y +K. The Routh table is given
by:
5
1 2
3 K
6 K
3
0
K 0
All the roots of the characteristic polynomial have a strictly negative real part if and only if
the elements of the rst row of the table are all nonzero and have all the same sign. This is
true if 0 < K < 6. What about K = 0 and K = 6? We can check that in these two cases, the
matrix has three distinct eigenvalues, it is thus diagonalizable and the solutions for these two
values 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 least
one 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 strictly
negative, 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 positive
real part and the solution is unstable.
6
2.2 Stability of critical points of a nonlinear ODE-system
Here, 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 xz
y

= x + 4y yz
z

= x
2
+y
2
89
with J
f
=
_
_
_
5 z 4 x
1 4 z y
2x 2y 0
_
_
_
where J
f
is the jacobian of f.
We compute the critical points by using Newtons method :

J
f
(u
i
) u
i
= f(u
i
)
u
i+1
= u
i
+ u
i
where J
f
(u
i
), f(u
i
) and u
i
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). We
know 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 stability
of a critical point from its jacobian. A critical point is asymptotically stable if and only if its
jacobian is negative denite
6
.
The MatLab function computes critical point is available in appendix A.5. We obtain the
following critical points :
(x; y; z) J
f
Stability
(7.94457; 5.08761; 2.43844)
_
_
_
2.56155 4 7.94457
1 1.56155 5.08761
15.88914 10.17522 0
_
_
_
10
15
13.34166i
10
15
+ 13.34166i
4.1231
Unstable
(7.94457; 5.08761; 2.43844)
_
_
_
2.56155 4 7.94457
1 1.56155 5.08761
15.88914 10.17522 0
_
_
_
10
15
13.34166i
10
15
+ 13.34166i
4.1231
Unstable
(8.78805; 3.43075; 6.56155)
_
_
_
1.56155 4 8.78805
1 2.56155 3.43075
17.57611 6.8615 0
_
_
_
0 13.34166i
0.0... 13.34166i
4.1231
Stable
(8.78805; 3.43075; 6.56155)
_
_
_
1.56155 4 8.78805
1 2.56155 3.43075
17.57611 6.8615 0
_
_
_
0 13.34166i
0.0... 13.34166i
4.1231
Stable
We note that the two last critical points have both a jacobian with 2 eigenvalues whose real
parts are near zero. But since MatLab returns 0.0..., we concluded that these two points are
asymptotically stable. Nevertheless, if we consider these eigenvalues have a zero real part, these
points are marginally stable as their associated jacobian are diagonalizable.
6. For further details see proposition 1
7
A Appendix
A.1 Marginal and asymptotic stability
In the section 1, we introduced the terms "asymptotically" and "marginally" stable. Here are
the denitions of these two concept
7
1. Marginal stability
Given R
n
an open set, f : R
n
a vector eld and t
0
R, then the point u
0
is
marginally stable (in the sense of Lyapunov) if
> 0, > 0 such that , x B(u
0
, ),
there exists a dierentiable function u : [t
0
, [R
n
such that t t
0
,
u(t) B(u
0
, )
u

(t) = f(u(t))
u(t
0
) = x
(6)
2. Asymptotic stability
Given R
n
an open set, f : R
n
a vector eld and t
0
R, then the point u
0
is
asymptotically stable if
it is marginally stable
there exists > 0 such that x B(u
0
, ),
if u is a solution of
_
_
_
u

(t) = f(u(t)) t [t
0
, [
u(t
0
) = x
(7)
then lim
t
u(t) = u
0
One can show that if a point u
0
is stable, then it has to be a critical point what means
that f(u
0
) = 0. In the case of an homogeneous system of dierential equation with constant
coecients of the type u

= Au, if A is nonsingular, the unique critical point is zero. In that


special case, we say that we analyze the "stability of the solution" when the initial condition is
nonzero. This means we actually analyze the stability of the point zero.
A.2 DN2221_lab1_Part1.m
1
2 % [DN2221 - Lab1]
3 % Part 1, Beaufort & Van Lierde
4 %%%%
5 % DN2221_lab1_Part1(t) is a function computes analytical solution of ODE
6 % equation Lq + Rq +1/C q = E, for some points contained in the vector t
7 % 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 = q
14 %%%%
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 direntielles ordinaires, Universit Catholique de Louvain, 2012, pp.75-77 (syllabus).
8
16
17 E = 10; %[V]
18 R = [0.1 1 10 100]; %[ohm]
19 L = 0.1; %[H]
20 C = 0.1; %[F]
21
22 sR = l engt h (R);
23 lT = l engt h (t);
24
25 f o r i = 1 : sR
26
27 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 r os (2,lT);
31 up = invA*Epsilon;
32 u0 = -up;
33 % analytical solution of ODE
34 % du/dt = A*u + Epsilon
35 % u(t=0) = u0
36 % is :
37
38 % - homogenous
39 f o r j = 1 : lT
40 u(:,j) = expm(A*t(j))*u0;
41 end
42 % - particular
43 u = u - up*ones(1,lT);
44
45 %display
46 s ubpl ot (2,sR,i)
47 pl ot (t,u(1,:) );
48 t i t l e ([Charge for R = , num2str (R(i)), ohm]);
49 gr i d on
50 xl abe l (Time [s])
51 yl abe l (Charge [C]);
52
53 %%%%%%
54
55 s ubpl ot (2,sR,i+sR)
56 pl ot (t,u(2,:) )
57 t i t l e ([Current for R = , num2str (R(i)),ohm]);
58 gr i d on
59 xl abe l (Time [s])
60 yl abe l (Current [A]);
61
62 end
63 end
A.3 DN2221_lab1_Part2a1.m
1 %% 2.a : Stability of a system - solution for different values of K
2 % This program computes the solution of the system described in the main
3 % document for four different values of K (0, 1, 4 and 8). The solutions
4 % are computed using the function expm. The total time of observation is
5 % 100s and the length of each time interval is 0.1s.
6
7 c l o s e a l l
8 k=[0 1 4 8];
9 y0 =[1;1;1];
10 t= l i ns pac e (1 ,100 ,1000);
11 f o r i=1: l engt h (k)
12 K=k(i);
13 A=[0 1 0;0 0 1;-K -2 -3];
14 y= z e r os (3, l engt h (t));
15 f o r j=1: l engt h (t)
16 y(:,j)=expm(A*t(j))*y0;
9
17 end
18 s ubpl ot (2,2,i);
19 pl ot (t,y(1,:));
20 xl abe l (time(s))
21 yl abe 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 Locus
2 % This program computes the eigen values of the matrix A for n different
3 % values of K between 0 and 10. It displays all the eigen values in the
4 % complex plane and it finds the limit value of K to obtain a stable
5 % solution.
6
7 n=500;
8 c l o s e a l l
9 K= l i ns pac e (0,10,n);
10 R= z e r os (1,3* l engt h (K));
11 indice =0;
12 found =0;
13
14 f o r k=1: l engt h (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:3
18 i f abs (imag(r(j))) <=1e-8
19 r(j)=r(j)+1i*1e-8;
20 end
21 i f r e a l (r(j)) >=0 && found ==0 && k~=1
22 found =1;
23 indice=k;
24 end
25 end
26 R(3*(k-1) +1:3*(k-1)+3)=r;
27 end
28
29 di s p (The limit value of K is)
30 K(indice)
31 f i g ur e
32 pl ot (R(1:3),ro)
33 hol d on
34 pl ot (R(3* l engt h (K) -2:3* l engt h (K)),go)
35 pl ot (R(3*( indice -1) +1:3*( indice -1) +3),ko)
36 pl ot (R(4:3* l engt h (K) -3),.)
37 gr i d on
38 xl abe l (Real Part)
39 yl abe l (Imaginary Part)
A.5 DN2221_lab1_Part2b.m
1
2
3
4 %
5 % DN2221 - lab1
6 % Part2b , Beaufort & Van Lierde
7 %
8 %%%%
9 % DN2221_lab1_Part2b(u0) computes critical point of the non -linear ODE , by
10 % 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 %%%%
15
16 f unc t i on [Ucrit ,Jf] = DN2221_lab1_Part2b(u0)
17
18
19 u = z e r os (2,3);
20
21 du = -J(u0)\f(u0);
22 Unew = u0 + du;
23 Uold = Unew + 1;
24 N = 0;
25
26 whi l e abs (Unew (1)-Uold (1)) >= 1e-5 && abs (Unew (2)-Uold (2)) >= 1e-5 && abs (Unew (3)-Uold (3)) >=
1e-5 && N <= 10
27
28 Uold = Unew;
29 du = -J(Uold)\f(Uold);
30 Unew = Uold + du;
31
32 N = N + 1;
33 end
34 N
35 Ucrit = Unew;
36 Jf = J(Ucrit);
37
38 end
39
40 f unc t i on F = f(u)
41
42 x = u(1);
43 y = u(2);
44 z = u(3);
45
46 F = [ 5*x + 4*y - x*z;
47 x + 4*y - y*z;
48 x^2 + y^2 - 89 ];
49
50 end
51
52 f unc t i on Jf = J(u)
53
54 x = u(1);
55 y = u(2);
56 z = u(3);
57
58 Jf = [5-z 4 -x ;
59 1 4-z -y ;
60 2*x 2*y 0 ];
61
62 end
11