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

  1. function [a, b] = d2c(phi, gamma, t)
  2. %D2C    Conversion of state space models from discrete to continuous time.
  3. %    [A, B] = D2C(Phi, Gamma, T)  converts the discrete-time system:
  4. %
  5. %        x[n+1] = Phi * x[n] + Gamma * u[n]
  6. %
  7. %    to the continuous-time state-space system:
  8. %        .
  9. %        x = Ax + Bu
  10. %
  11. %    assuming a zero-order hold on the inputs and sample time T.
  12. %
  13. %    See also: D2CM and C2D.
  14.  
  15. %    J.N. Little 4-21-85
  16. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  17. %    Revised 9-22-88 JNL  Phi=1 case fixed,
  18. %    10-17-90 A.Grace Better logm, and handles rows of zeros in gamma.
  19.  
  20. error(nargchk(3,3,nargin));
  21. error(abcdchk(phi,gamma));
  22.  
  23. [m,n] = size(phi);
  24. [m,nb] = size(gamma);
  25.  
  26. % phi = 1 case cannot be computed through matrix logarithm.  Handle
  27. % as a special case.
  28. if m == 1
  29.     if phi == 1
  30.         a = 0; b = gamma/t;
  31.         return
  32.     end
  33. end
  34.  
  35. % Remove rows in gamma that correspond to all zeros
  36. b = zeros(m,nb);
  37. nz = 0;
  38. nonzero = [];
  39. for i=1:nb
  40.     if any(gamma(:,i)~=0) 
  41.         nonzero = [nonzero, i];
  42.         nz = nz + 1;
  43.     end
  44. end
  45.  
  46. % Do rest of cases using matrix logarithm.
  47.  
  48. s = logm2([[phi gamma(:,nonzero)]; zeros(nz,n) eye(nz)])/t;
  49. if norm(imag(s),'inf') > sqrt(eps); 
  50.     disp('Warning: Accuracy of d2c conversion may be poor.')
  51. end
  52. s = real(s);
  53. a = s(1:n,1:n);
  54. if length(b)
  55.     b(:,nonzero) = s(1:n,n+1:n+nz);
  56. end
  57.