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

  1. # Copyright (C) 1997 Kai P. Mueller
  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 the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function Qs = ctrb(sys, b)
  18.   # ------------------------------------------------------
  19.   # Qs = ctrb(sys [, b])
  20.   # Build controllability matrix
  21.   #
  22.   #                  2       n-1
  23.   #     Qs = [ B AB A B ... A   B
  24.   #
  25.   # of a system data structure or the pair (A, B).
  26.   #
  27.   # Note: ctrb() forms the controllability matrix.
  28.   #       The numerical properties of is_controllable()
  29.   #       are much better for controllability tests.
  30.   # See also: obsv, is_observable, is_controllable
  31.   # ------------------------------------------------------
  32.  
  33.   # Written by Kai P. Mueller November 4, 1997
  34.   # based on is_controllable.m of Scottedward Hodel
  35.   # modified by
  36.  
  37.   if (nargin == 2)
  38.     a = sys;
  39.   elseif (nargin == 1 && is_struct(sys))
  40.     sysupdate(sys,"ss");
  41.     [a,b] = sys2ss(sys);
  42.   else
  43.     usage("ctrb(sys [, b])")
  44.   endif
  45.  
  46.   if (!is_abcd(a,b))
  47.     Qs = [];
  48.   else
  49.     # no need to check dimensions, we trust is_abcd().
  50.     [na, ma] = size(a);
  51.     # using imb avoids name conflict with the "mb" function
  52.     [inb, imb] = size(b);
  53.     Qs = zeros(na, ma*imb);
  54.     for i = 1:na
  55.       Qs(:, (i-1)*imb+1:i*imb) = b;
  56.       b = a * b;
  57.     endfor
  58.   endif
  59. endfunction
  60.