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

  1. function k = dcgain(a,b,c,d)
  2. %DCGAIN D.C. gain of continuous system.
  3. %    K = DCGAIN(A,B,C,D) computes the steady state (D.C. or low 
  4. %    frequency) gain of the continuous state-space system (A,B,C,D).
  5. %
  6. %    K = DCGAIN(NUM,DEN) computes the steady state gain of the 
  7. %    continuous polynomial transfer function system G(s)=NUM(s)/DEN(s)
  8. %    where NUM and DEN contain the polynomial coefficients in 
  9. %    descending powers of s.
  10. %
  11. %    See also: DDCGAIN.
  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.   n = length(den);
  21.   if (n == 0 | length(num) == 0)
  22.       k = [];
  23.   else
  24.       k = num(:,n)/den(n);
  25.   end
  26.  
  27. elseif nargin==4, % State space description
  28.   error(abcdchk(a,b,c,d));
  29.   if any(abs(eig(a))<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(a);
  33.     ndx = find(abs(diag(u))<eps);
  34.     if length(ndx)>0, 
  35.        % Make a very small number.
  36.        u(ndx,ndx) = -1.e-300*ones(length(ndx)); 
  37.     end 
  38.     k = -c*(u\(l\b)) + d;
  39.     % Note there is caveat here. If the inverse has all infinites in it
  40.     % and the C matrix has some zero elements, Nans may propogate when the 
  41.     % true solution should have inifinites in it.
  42.     out = find(abs(k)>1.e+200);
  43.     if length(out)>0, k(out) = inf*sign(k(out)); end
  44.   else
  45.     k = -c/a*b + d;
  46.   end
  47. else
  48.   error('Wrong number of input arguments.');
  49. end
  50.