home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / is_stable.m < prev    next >
Text File  |  1999-03-05  |  2KB  |  64 lines

  1. # Copyright (C) 1993, 1994, 1995 John W. Eaton
  2. # This file is part of Octave.
  3. # Octave is free software; you can redistribute it and/or modify it
  4. # under the terms of the GNU General Public License as published by the
  5. # Free Software Foundation; either version 2, or (at your option) any
  6. # later version.
  7. # Octave is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  10. # for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with Octave; see the file COPYING.  If not, write to the Free
  13. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  14.  
  15. function retval = is_stable (a, tol, disc)
  16.  
  17. # Usage: retval = is_stable (a {,tol,disc})
  18. # or     retval = is_stable (sys{,tol})
  19. #
  20. # Returns retval = 1 if the matrix a or the system a is stable, or 0 if not.
  21. #
  22. # tol is a roundoff paramter, set to 200*eps if omitted.
  23. # disc != 0: stable if eig(a) in unit circle
  24. #         0: stable if eig(a) in open LHP (default)
  25. #
  26. # See also: size, rows, columns, length, is_matrix, is_scalar, is_vector
  27. #     is_observable, is_stabilizable, is_detectable, krylov, krylovb
  28.  
  29. # Written by A. S. Hodel (scotte@eng.auburn.edu) August, 1993.
  30. # Updated by John Ingram (ingraje@eng.auburn.edu) July, 1996 for systems
  31. # Updated to simpler form by a.s.hodel 1998
  32.  
  33.   if( (nargin < 1) | (nargin > 3) )   usage("is_stable(a {,tol,disc})");
  34.   elseif(is_struct(a))
  35.     # system was passed
  36.     if(nargin < 3)            disc = is_digital(a);
  37.     elseif(disc != is_digital(a))
  38.       warning("is_stable: disc =%d does not match system",disc)
  39.     endif
  40.     sys = sysupdate(a,"ss");
  41.     a = sys2ss(sys);
  42.   else
  43.     if(nargin < 3)        disc = 0;        endif
  44.     if(is_square(a) == 0)
  45.       error("A(%dx%d) must be square",rows(A), columns(A));
  46.     endif
  47.   endif
  48.  
  49.   if(nargin < 2)        tol = 200*eps;
  50.   elseif( !is_scalar(tol) )
  51.     error("is_stable: tol(%dx%d) must be a scalar",rows(tol),columns(tol));
  52.   endif
  53.  
  54.   l = eig(a);
  55.   if(disc)    nbad = sum(abs(l)*(1+tol) > 1);
  56.   else        nbad = sum(real(l)+tol > 0);        endif
  57.   retval = (nbad == 0);   
  58.  
  59. endfunction
  60.