home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / control / dcgain.m < prev    next >
Encoding:
Text File  |  1999-12-15  |  1.8 KB  |  52 lines

  1. ## Copyright (C) 1993, 1994, 1995 John W. Eaton
  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{gm} =} dcgain(@var{sys}@{, tol@})
  21. ##       Returns dc-gain matrix. If dc-gain is infinite
  22. ##       an empty matrix is returned.
  23. ##       The argument @var{tol} is an optional tolerance for the condition
  24. ##       number of @var{A}-Matrix in @var{sys} (default @var{tol} = 1.0e-10)
  25. ## @end deftypefn
  26.  
  27. function gm = dcgain (sys, tol)
  28. ## Written by Kai P Mueller (mueller@ifr.ing.tu-bs.de) October 1, 1997
  29.  
  30.   if((nargin < 1) || (nargin > 2) || (nargout > 1))
  31.     usage("[gm, ok] = dcgain(sys[, tol])");
  32.   endif
  33.   if(!is_struct(sys))
  34.     error("dcgain: first argument is not a system data structure.")
  35.   endif
  36.   sys = sysupdate(sys, "ss");
  37.   [aa,bb,cc,dd] = sys2ss(sys);
  38.   if (is_digital(sys))  aa = aa - eye(size(aa));  endif
  39.   if (nargin == 1)  tol = 1.0e-10;  endif
  40.   r = rank(aa, tol);
  41.   if (r < rows(aa))
  42.     gm = [];
  43.   else
  44.     gm = -cc / aa * bb + dd;
  45.   endif
  46.   if(!is_stable(sys))
  47.     [nn,nz,mm,pp] = sysdimensions(sys);
  48.     warning("dcgain: unstable system; dimensions [nc=%d,nz=%d,mm=%d,pp=%d]", ...
  49.       nn,nz,mm,pp);
  50.   endif
  51. endfunction
  52.