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

  1. function [yout,x,n] = dinitial(a,b,c,d,x0,n)
  2. %DINITIAL Initial condition response of discrete-time linear systems.
  3. %    DINITIAL(A,B,C,D,X0) plots the time response of the discrete
  4. %    system:
  5. %        x[n+1] = Ax[n] + Bu[n]
  6. %        y[n]   = Cx[n] + Du[n]
  7. %
  8. %    due to an initial condition on the states.  The number of sample
  9. %    points is automatically determined based on the system poles and
  10. %    zeros.  
  11. %
  12. %    DINITIAL(A,B,C,D,X0,N) uses the user-supplied number of points, N.
  13. %    When invoked with left hand arguments:
  14. %        [Y,X] = DINITIAL(A,B,C,D,X0,...)
  15. %    returns the output and state responses (Y and X).  No plot is 
  16. %    drawn on the screen.  The matrix Y has as many columns as outputs
  17. %    and X has as many columns as there are states.
  18. %    
  19. %    See also: DIMPULSE,DSTEP,DLSIM, and INITIAL.
  20.  
  21. %    Clay M. Thompson  7-6-90
  22. %    Revised ACWG 6-21-92
  23. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  24.  
  25. if nargin==0, eval('exresp(''dinitial'',1)'), return, end
  26.  
  27. error(nargchk(4,6,nargin));
  28. error(abcdchk(a,b,c,d));
  29.  
  30. [ny,nu] = size(d);
  31. if (nu*ny==0)|isempty(a),
  32.     x = []; n = []; if nargout~=0, yout=[]; end, return,
  33. end
  34.  
  35. [nx,na] = size(a);
  36. if nargin==4,        % No x0 specified, use random initial condition.
  37.     x0 = randn(nx,1);
  38.  
  39. else
  40.     x0 = x0(:);        % Make sure x0 is a column vector
  41.     if length(x0)~=nx,
  42.         error('The length of X0 must be equal to the number of states.');
  43.     end
  44. end
  45.  
  46. if (nargin==4)|(nargin==5)  % Workout time vector if not supplied.
  47.     % The next line controls the number of samples in the plot if N not specified
  48.     st=0.005; % Set settling time bound  = 0.5%
  49.     n=dtimvec(a,b,c,x0,st);
  50. end
  51.  
  52.  
  53. % --- Simulation ---
  54. [nx,nu] = size(b);
  55. [y,x] = dlsim(a,b,c,d,zeros(n,nu),x0(:));
  56.  
  57. % Plot Graph
  58. if nargout==0
  59.     status = ishold;
  60.     stairs([0:n-1],y)
  61.     hold on
  62.     plot([0,n-1],[0;0],':')
  63.     xlabel('Sample Number'), ylabel('Amplitude')
  64.  
  65.     if ~status, hold off, end    % Return hold to previous status
  66.     return % Suppress output
  67. end
  68. yout = y; 
  69.