Mercurial > octave-nkf
comparison scripts/control/lyap.m @ 53:4565ad8b4697
[project @ 1993-08-11 21:21:34 by jwe]
author | jwe |
---|---|
date | Wed, 11 Aug 1993 21:21:34 +0000 |
parents | adade67872a7 |
children | 8d4431f4a00a |
comparison
equal
deleted
inserted
replaced
52:9eda1009cf95 | 53:4565ad8b4697 |
---|---|
1 function x = lyap(a,b,c) | 1 function x = lyap (a, b, c) |
2 | 2 |
3 % usage: x = lyap(a,b{,c}) | 3 # usage: x = lyap (a, b {,c}) |
4 % | 4 # |
5 % If (a,b,c) are specified, then lyap returns the solution of the Sylvester | 5 # If (a, b, c) are specified, then lyap returns the solution of the |
6 % equation | 6 # Sylvester equation |
7 % a x + x b + c = 0 | 7 # |
8 % | 8 # a x + x b + c = 0 |
9 % If only (a,b) are specified, then lyap returns the solution of the | 9 # |
10 % Lyapunov equation | 10 # If only (a, b) are specified, then lyap returns the solution of the |
11 % a' x + x a + b = 0 | 11 # Lyapunov equation |
12 % If b is not square, then lyap returns the solution of either | 12 # |
13 % a' x + x a + b' b = 0 | 13 # a' x + x a + b = 0 |
14 % or | 14 # |
15 % a x + x a' + b b' = 0 | 15 # If b is not square, then lyap returns the solution of either |
16 % whichever is appropriate. | 16 # |
17 # a' x + x a + b' b = 0 | |
18 # | |
19 # or | |
20 # | |
21 # a x + x a' + b b' = 0 | |
22 # | |
23 # whichever is appropriate. | |
17 | 24 |
18 if((nargin ~= 3) && (nargin ~= 2)) | 25 if (nargin != 3 && nargin != 2) |
19 error("lyap: illegal number of arguments") | 26 error ("lyap: illegal number of arguments"); |
20 return | 27 return; |
21 endif | 28 endif |
22 | 29 |
23 if( (n = is_square(a)) == 0 ) | 30 if ((n = is_square(a)) == 0) |
24 error("lyap: a is not square"); | 31 error ("lyap: a is not square"); |
25 return | 32 return; |
26 endif | 33 endif |
27 | 34 |
28 if(nargin == 2) | 35 if (nargin == 2) |
29 disp('LYAP') | 36 |
30 a=a | 37 # Transform Lyapunov equation to Sylvester equation form. |
31 b=b | 38 |
32 % transform Lyapunov equation to Sylvester equation form | 39 if ((m = is_square (b)) == 0) |
33 if ( (m=is_square(b)) == 0) | 40 if ((m = rows (b)) == n) |
34 if( (m=rows(b)) == n) | 41 |
35 disp('TYPE CONTROL') | 42 # solve a x + x a' + b b' = 0 |
36 % solve a x + x a' + b b' = 0 | 43 |
37 b = b*b'; | 44 b = b * b'; |
38 a = a'; | 45 a = a'; |
39 else | 46 else |
40 disp('TYPE OBSERVE') | 47 |
41 % (try to ) solve a'x + x a + b' b = 0 | 48 # Try to solve a'x + x a + b' b = 0. |
42 m = columns(b); | 49 |
43 b = b'*b; | 50 m = columns (b); |
51 b = b' * b; | |
52 endif | |
53 | |
54 if (m != n) | |
55 error ("lyap: a, b not conformably dimensioned"); | |
56 return; | |
57 endif | |
44 endif | 58 endif |
45 if(m ~= n) | 59 |
46 error("lyap: a, b not conformably dimensioned"); | 60 # Set up Sylvester equation. |
61 | |
62 c = b; | |
63 b = a; | |
64 a = b' | |
65 | |
66 else | |
67 | |
68 # Check dimensions. | |
69 | |
70 if ((m = is_square (b)) == 0) | |
71 error ("lyap: b must be square in a sylvester equation"); | |
47 return; | 72 return; |
48 endif | 73 endif |
74 | |
75 [n1,m1] = size(c); | |
76 | |
77 if (n != n1 || m != m1) | |
78 error("lyap: a,b,c not conformably dimensioned"); | |
79 endif; | |
49 endif | 80 endif |
50 | 81 |
51 % set up sylvester equation | 82 # Call octave built-in function. |
52 c = b; | |
53 b = a; | |
54 a = b' | |
55 else | |
56 % check dimensions | |
57 if( (m = is_square(b)) == 0) | |
58 error("lyap: b must be square in a sylvester equation"); | |
59 return | |
60 endif | |
61 [n1,m1] = size(c); | |
62 if((n ~= n1) || (m ~= m1)) | |
63 error("lyap: a,b,c not conformably dimensioned"); | |
64 endif | |
65 endif | |
66 a | |
67 b | |
68 c | |
69 | 83 |
70 % call octave built-in function | 84 x = syl(a,b,c); |
71 x = syl(a,b,c); | |
72 | 85 |
73 disp('LYAP ERR') | |
74 a*x + x*b + c | |
75 a=a | |
76 b=b | |
77 c=c | |
78 endfunction | 86 endfunction |