aminit;					% initialize MATALB

%Simulation of PI control
t=0:0.1:20;one=ones(size(t)); zero=0*one;
den=conv([1 1],[1 2 1]);
P=tf(1,den);
y=[];u=[];
for ki=[0 0.2 0.5 1],
   C=tf([1 ki],[1 0]);
   [y0,t]=step(P*C/(1+P*C),t);
   [u0,t]=step(C/(1+P*C),t);
   y=[y,y0];u=[u u0];
end

figure(1); clf;

subplot(331)
plot(t,one,'k-', 'LineWidth', AM_ref_linewidth); hold on;
pl=plot(t,y(:,1),'b-',t,y(:,2),'b-',t,y(:,3),'b-',t,y(:,4),'b-');
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 20 0 1.725]); 
%xlabel('x'); 
ylabel('y')

arcarrow([11 0.4], [15 1.3], -20);
amtext(15, 1.45, 'ki');

subplot(334)
plot(t,zero,'k-', 'LineWidth', AM_ref_linewidth); hold on;
pl=plot(t,u(:,1),'b-',t,u(:,2),'b-',t,u(:,3),'b-',t,u(:,4),'b-');
set(pl,'Linewidth', AM_data_linewidth)
% set(gca,'Ytick',[0 1 2])
amaxis([0 20 -2 5]); 
xlabel('x');ylabel('u');

arcarrow([2 0.2], [5 2.2], -10);
amtext(5.5, 2.7, 'ki');

amprint('picon.eps');

