home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / is_controllable.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  97 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,U] = is_controllable (a, b, tol)
  16. # [retval, U] = is_controllable (a, b {,tol})
  17. #             = is_controllable (sys{, tol})
  18. #      Returns retval=1 if the system sys or the pair (a, b) is controllable
  19. #                     0 if not.
  20. # U is an orthogonal basis of the controllable subspace. 
  21. #
  22. # Controllability is determined by applying Arnoldi iteration with
  23. # complete re-orthogonalization to obtain an orthogonal basis of the
  24. # Krylov subspace.
  25. #
  26. #   span ([b,a*b,...,a^   b]).
  27. #
  28. # tol is a roundoff paramter, set to 10*eps if omitted.
  29. #
  30. # See also: size, rows, columns, length, is_matrix, is_scalar, is_vector
  31. #     is_observable, is_stabilizable, is_detectable, krylov, krylovb
  32.  
  33. # Written by A. S. Hodel (scotte@eng.auburn.edu) August, 1993.
  34. # Updated by A. S. Hodel (scotte@eng.auburn.edu) Aubust, 1995 to use krylovb 
  35. # Updated by John Ingram (ingraje@eng.auburn.edu) July, 1996 for packed systems
  36.  
  37.   deftol = 1;    # assume default tolerance
  38.   if(nargin < 1 | nargin > 3)
  39.     usage("[retval,U] = %s\n\t%s", "is_controllable(a {, b ,tol})", ...
  40.     "is_controllable(sys{,tol})");
  41.   elseif(is_struct(a))
  42.     # system structure passed.
  43.     sys = sysupdate(a,"ss");
  44.     [a,bs] = sys2ss(sys);
  45.     if(nargin > 2)
  46.       usage("[retval,U] = is_controllable(sys{,tol})");
  47.     elseif(nargin == 2)
  48.       tol = b;        % get tolerance
  49.       deftol = 0;
  50.     endif
  51.     b = bs;
  52.   else
  53.     # a,b arguments sent directly.
  54.     if(nargin < 2)
  55.       usage("[retval,U] = is_controllable(a {, b ,tol})");
  56.     else
  57.       deftol = 1;
  58.     endif
  59.   endif
  60.  
  61.   # check for default tolerance
  62.   if(deftol) tol = 1000*eps; endif
  63.  
  64.   # check tol dimensions
  65.   if( !is_scalar(tol) )
  66.     error("is_controllable: tol(%dx%d) must be a scalar", ...
  67.     rows(tol),columns(tol));
  68.   elseif( !is_sample(tol) )
  69.     error("is_controllable: tol=%e must be positive",tol);
  70.   endif
  71.  
  72.   # check dimensions compatibility
  73.   n = is_square (a);
  74.   [nr, nc] = size (b);
  75.  
  76.   if (n == 0 | n != nr | nc == 0)
  77.     warning("is_controllable: a=(%dx%d), b(%dx%d)",rows(a),columns(a),nr,nc);
  78.     retval = 0;
  79.   else
  80.     # call block-krylov subspace routine to get an orthogonal basis
  81.     # of the controllable subspace.
  82.     if(nc == 1)
  83.       [U,H,Ucols] = krylov(a,b,n,tol,1);
  84.       U = U(:,1:Ucols);
  85.     else
  86.       [U,Ucols] = krylovb(a,b,n,tol);
  87.       U = U(:,1:Ucols);
  88.     endif
  89.  
  90.     retval = (Ucols == n);
  91.   endif
  92. endfunction
  93.