home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / dcgain.m < prev    next >
Text File  |  1999-04-29  |  2KB  |  52 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 gm = dcgain(sys, tol)
  16. # Usage: gm = dcgain(sys[, tol])
  17. #      Returns dc-gain matrix. If dc-gain is infinity
  18. #      an empty matrix is returned.
  19. #      The argument tol is an optional tolerance for the condition
  20. #      number of A-Matrix in sys (default tol = 1.0e-10)
  21. #      Prints a warning message of the system is unstable.
  22. #
  23.  
  24. # Written by Kai P Mueller (mueller@ifr.ing.tu-bs.de) October 1, 1997
  25.  
  26.   if((nargin < 1) || (nargin > 2) || (nargout > 1))
  27.     usage("[gm, ok] = dcgain(sys[, tol])");
  28.   endif
  29.   if(!is_struct(sys))
  30.     error("dcgain: first argument is not a system data structure.")
  31.   endif
  32.   sys = sysupdat(sys, "ss");
  33.   [aa,bb,cc,dd] = sys2ss(sys);
  34.   if (is_digit(sys))  aa = aa - eye(size(aa));  endif
  35.   if (nargin == 1)  tol = 1.0e-10;  endif
  36.   r = rank(aa, tol);
  37.   if (r < rows(aa))
  38.     gm = [];
  39.   else
  40.     gm = -cc / aa * bb + dd;
  41.   endif
  42.   if(!is_stabl(sys))
  43.     [nn,nz,mm,pp] = sysdimen(sys);
  44.     warning("dcgain: unstable system; dimensions [nc=%d,nz=%d,mm=%d,pp=%d]", ...
  45.       nn,nz,mm,pp);
  46.   endif
  47. endfunction
  48.