home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / ctrb.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  1.9 KB  |  64 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. ## 
  10. ## Octave is distributed in the hope that it will be useful, but WITHOUT 
  11. ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  12. ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  13. ## 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 02111 USA. 
  18.  
  19. ## -*- texinfo -*-
  20. ## @deftypefn {Function File } {@var{Qs} =} ctrb(@var{sys} @{, @var{b}@})
  21. ## @deftypefnx {Function File } {@var{Qs} =} ctrb(@var{A}, @var{B})
  22. ## Build controllability matrix
  23. ## @example
  24. ##              2       n-1
  25. ## Qs = [ B AB A B ... A   B ]
  26. ## @end example
  27. ## 
  28. ##  of a system data structure or the pair (@var{A}, @var{B}).
  29. ## 
  30. ## @strong{Note} @code{ctrb} forms the controllability matrix.
  31. ##        The numerical properties of @code{is_controllable}
  32. ##        are much better for controllability tests.
  33. ## @end deftypefn
  34.  
  35. function Qs = ctrb (sys, b)
  36.  
  37.   ## Written by Kai P. Mueller November 4, 1997
  38.   ## based on is_controllable.m of Scottedward Hodel
  39.   ## modified by
  40.  
  41.   if (nargin == 2)
  42.     a = sys;
  43.   elseif (nargin == 1 && is_struct(sys))
  44.     sysupdate(sys,"ss");
  45.     [a,b] = sys2ss(sys);
  46.   else
  47.     usage("ctrb(sys [, b])")
  48.   endif
  49.  
  50.   if (!is_abcd(a,b))
  51.     Qs = [];
  52.   else
  53.     ## no need to check dimensions, we trust is_abcd().
  54.     [na, ma] = size(a);
  55.     ## using imb avoids name conflict with the "mb" function
  56.     [inb, imb] = size(b);
  57.     Qs = zeros(na, ma*imb);
  58.     for i = 1:na
  59.       Qs(:, (i-1)*imb+1:i*imb) = b;
  60.       b = a * b;
  61.     endfor
  62.   endif
  63. endfunction
  64.