2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
2311
|
20 ## Usage: x = lyap (a, b {,c}) |
|
21 ## |
|
22 ## If (a, b, c) are specified, then lyap returns the solution of the |
|
23 ## Sylvester equation |
|
24 ## |
|
25 ## a x + x b + c = 0 |
|
26 ## |
2325
|
27 ## If only (a, b) are specified, then lyap returns the solution of the |
2311
|
28 ## Lyapunov equation |
|
29 ## |
|
30 ## a' x + x a + b = 0 |
|
31 ## |
|
32 ## If b is not square, then lyap returns the solution of either |
|
33 ## |
2325
|
34 ## a' x + x a + b' b = 0 |
2311
|
35 ## |
|
36 ## or |
|
37 ## |
|
38 ## a x + x a' + b b' = 0 |
|
39 ## |
|
40 ## whichever is appropriate. |
|
41 ## |
|
42 ## Solves by using the Bartels-Stewart algorithm (1972). |
40
|
43 |
2312
|
44 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
|
45 ## Created: August 1993 |
|
46 ## Adapted-By: jwe |
73
|
47 |
2312
|
48 function x = lyap (a, b, c) |
40
|
49 |
53
|
50 if (nargin != 3 && nargin != 2) |
904
|
51 usage ("lyap (a, b {,c})"); |
53
|
52 endif |
|
53 |
|
54 if ((n = is_square(a)) == 0) |
|
55 error ("lyap: a is not square"); |
|
56 endif |
|
57 |
|
58 if (nargin == 2) |
40
|
59 |
2303
|
60 ## Transform Lyapunov equation to Sylvester equation form. |
53
|
61 |
|
62 if ((m = is_square (b)) == 0) |
|
63 if ((m = rows (b)) == n) |
|
64 |
2303
|
65 ## solve a x + x a' + b b' = 0 |
53
|
66 |
|
67 b = b * b'; |
|
68 a = a'; |
2325
|
69 else |
53
|
70 |
2303
|
71 ## Try to solve a'x + x a + b' b = 0. |
53
|
72 |
|
73 m = columns (b); |
|
74 b = b' * b; |
|
75 endif |
40
|
76 |
53
|
77 if (m != n) |
|
78 error ("lyap: a, b not conformably dimensioned"); |
|
79 endif |
40
|
80 endif |
53
|
81 |
2303
|
82 ## Set up Sylvester equation. |
53
|
83 |
|
84 c = b; |
|
85 b = a; |
1194
|
86 a = b'; |
53
|
87 |
2325
|
88 else |
53
|
89 |
2303
|
90 ## Check dimensions. |
53
|
91 |
|
92 if ((m = is_square (b)) == 0) |
|
93 error ("lyap: b must be square in a sylvester equation"); |
40
|
94 endif |
53
|
95 |
73
|
96 [n1, m1] = size(c); |
53
|
97 |
|
98 if (n != n1 || m != m1) |
|
99 error("lyap: a,b,c not conformably dimensioned"); |
1194
|
100 endif |
40
|
101 endif |
|
102 |
2303
|
103 ## Call octave built-in function. |
40
|
104 |
73
|
105 x = syl (a, b, c); |
40
|
106 |
|
107 endfunction |