7017
|
1 ## Copyright (C) 1993, 1994, 1995, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3441
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3441
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3441
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3441
|
19 |
|
20 ## -*- texinfo -*- |
3500
|
21 ## @deftypefn {Function File} {} is_stable (@var{a}, @var{tol}, @var{dflg}) |
|
22 ## @deftypefnx {Function File} {} is_stable (@var{sys}, @var{tol}) |
|
23 ## Returns 1 if the matrix @var{a} or the system @var{sys} |
3441
|
24 ## is stable, or 0 if not. |
|
25 ## |
|
26 ## @strong{Inputs} |
|
27 ## @table @var |
|
28 ## @item tol |
5016
|
29 ## is a roundoff parameter, set to 200*@code{eps} if omitted. |
3441
|
30 ## @item dflg |
|
31 ## Digital system flag (not required for system data structure): |
|
32 ## @table @code |
|
33 ## @item @var{dflg} != 0 |
5016
|
34 ## stable if eig(a) is in the unit circle |
3441
|
35 ## |
|
36 ## @item @var{dflg} == 0 |
5016
|
37 ## stable if eig(a) is in the open LHP (default) |
3441
|
38 ## @end table |
|
39 ## @end table |
5642
|
40 ## @seealso{size, rows, columns, length, ismatrix, isscalar, isvector |
|
41 ## is_observable, is_stabilizable, is_detectable, krylov, krylovb} |
3441
|
42 ## @end deftypefn |
|
43 |
|
44 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
45 ## Created: August 1993 |
|
46 ## Updated by John Ingram (ingraje@eng.auburn.edu) July, 1996 for systems |
|
47 ## Updated to simpler form by a.s.hodel 1998 |
|
48 |
|
49 function retval = is_stable (a, tol, disc) |
|
50 |
7136
|
51 if (nargin < 1 || nargin > 3) |
|
52 print_usage (); |
|
53 elseif (isstruct (a)) |
3441
|
54 ## system was passed |
7136
|
55 if (nargin < 3) |
|
56 disc = is_digital(a); |
|
57 elseif (disc != is_digital (a)) |
|
58 warning ("is_stable: disc =%d does not match system", disc) |
3441
|
59 endif |
7136
|
60 sys = sysupdate (a, "ss"); |
|
61 a = sys2ss (sys); |
3441
|
62 else |
7136
|
63 if (nargin < 3) |
|
64 disc = 0; |
|
65 endif |
|
66 if (issquare (a) == 0) |
|
67 error ("A(%dx%d) must be square", rows (A), columns (A)); |
3441
|
68 endif |
|
69 endif |
|
70 |
7136
|
71 if (nargin < 2) |
|
72 tol = 200*eps; |
|
73 elseif (! isscalar (tol)) |
|
74 error ("is_stable: tol(%dx%d) must be a scalar", rows (tol), |
|
75 columns (tol)); |
3441
|
76 endif |
|
77 |
7136
|
78 l = eig (a); |
|
79 if (disc) |
|
80 nbad = sum (abs(l)*(1+tol) > 1); |
|
81 else |
|
82 nbad = sum (real(l)+tol > 0); |
|
83 endif |
3441
|
84 retval = (nbad == 0); |
|
85 |
|
86 endfunction |