home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 10.ddi / CONTROL.DI$ / DDCGAIN.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.3 KB  |  45 lines

  1. function k = ddcgain(a,b,c,d)
  2. %DDCGAIN D.C. gain of discrete system.
  3. %    K = DDCGAIN(A,B,C,D) computes the steady state (D.C. or low 
  4. %    frequency) gain of the discrete state-space system (A,B,C,D).
  5. %
  6. %    K = DDCGAIN(NUM,DEN) computes the steady state gain of the 
  7. %    discrete polynomial transfer function system G(z) = NUM(z)/DEN(z)
  8. %    where NUM and DEN contain the polynomial coefficients in 
  9. %    descending powers of z.
  10. %
  11. %    See also: DCGAIN.
  12.  
  13. %    Clay M. Thompson  7-6-90
  14. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  15.  
  16. error(nargchk(2,4,nargin));
  17.  
  18. if (nargin==2), % Transfer function description
  19.   [num,den] = tfchk(a,b);
  20.   if (length(num) & length(den))
  21.     k = sum(num')'/sum(den);
  22.   else
  23.     k = [];
  24.   end
  25.  
  26. elseif nargin==4, % State space description
  27.   error(abcdchk(a,b,c,d));
  28.   [nx,na] = size(a);
  29.   if any(abs(eig(a)-1)<eps), % System is singular.
  30.     % Use LU decomposition to solve system.  Put a very small number in place
  31.     % of the singularity.  Set to INF if necessary after calculation.
  32.     [l,u] = lu(eye(nx)-a);
  33.     ndx = find(abs(diag(u))<eps);
  34.     if length(ndx)>0, u(ndx,ndx) = 1.e-300; end % A very small number.
  35.     k = c*(u\(l\b)) + d;
  36.     out = find(abs(k)>1.e+200);
  37.     if length(out)>0, k(out) = inf*sign(k(out)); end
  38.   else
  39.     k = c/(eye(nx)-a)*b + d;
  40.   end
  41.  
  42. else
  43.   error('Wrong number of input arguments.');
  44. end
  45.