%Develop error step response by standard matrix procedure
%  alpha = 1, zeta = 0.5, Wn = 1
%  Step Input

% Generate vector of computation times:
inc = .05; %sampling period
ending = 10; % Student Matlab limits ending/inc to 1024 in v.3.5, 8192 in v.4
last = 1 + ending/inc; % index of last data points
t = linspace(0,ending,last); % linear sequence of times
dt = t(2) - t(1); % time increment

% Generate input step vector:
u = ones(1,last); % unit step input; column vector with input at each time

clg; % clear previous graphs

NUM = [1 0 0]; % for error response, as before
DEN = [1 1 1]; % denstep from ErTrn1a
[a,b,c,d] = tf2ss(NUM,DEN); 
% get elements of dynamic matrix equation [c is bottom row of C and d is bottom row of D in Eq. (6.44)]
[Phi, Gamma] = c2d(a,b,dt); % get matrices for use in solution
x = ltitr(Phi,Gamma,u'); % state variable solution for each value of t
y = c*x'+d*u; % outputs.  x is transpose of X in Eq. (6.33); y is lower element in Eq. (6.45)
    % x',y and u have a column for each time increment

plot(t,y) 
grid
title('Time Response, Error, Step Input')
xlabel('seconds')
ylabel('radians')

		
		

