forked from yeoleparesh/Control-system
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dlyap.sci
67 lines (65 loc) · 1.66 KB
/
dlyap.sci
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function X = dlyap(A,B,C,E)
// DLYAP Solve discrete Lyapunov equations.
//
// X = DLYAP(A,C) solves the discrete Lyapunov matrix equation:
//
// A'*X*A-X +C=0
//
// X = DLYAP(A,B,C) solves the Sylvester equation:
//
// A*X*B - X +C =0
//
// X = DLYAP(A,C,[],E) solves the generalized discrete Lyapunov equation:
//
// A*X*A' - E*X*E' +C =0
//
//Note:-The discrete-time Lyapunov equation has a unique solution X, for any C = C'
// if and only if λi(A)λj(A)<>1, for i,j = 1, . . . , n.
//
//References:-
// http://stanford.edu/class/ee363/notes/lq-lyap-notes.pdf
//
////Examples:-
//A = [3.0 1.0 1.0
// 1.0 3.0 0.0
// 0.0 0.0 3.0];
//
// B = [25.0 24.0 15.0
// 24.0 32.0 8.0
// 15.0 8.0 40.0];
//
// X = dlyap (A, B);
//
//
// Sylvester
// A = [1.0 2.0 3.0
// 6.0 7.0 8.0
// 9.0 2.0 3.0];
//
// B = [7.0 2.0 3.0
// 2.0 1.0 2.0
// 3.0 4.0 1.0];
//
// C = [271.0 135.0 147.0
// 923.0 494.0 482.0
// 578.0 383.0 287.0];
//
// X = dlyap (A, B, C);
//
////Author:Paresh Yeole emailid:-yeoleparesh@students.vnit.ac.in
[lhs rhs]=argn(0);
select rhs
case 2 then
X=lyap(A.',-B,'d');
case 3 then
X=sylv(-A,B,C,'d');
case 4 then
if C<>[] then
error("dlyap:for generalised lyapunov equation the third input argument must be empty square brackets []");
end
X=lyap(inv(E)*(A.'),inv(E)*(-B),'d');
else
error("dlyap:wrong no. of input arguments");
end
//X=linmeq(2,A,C,flag)
endfunction