aminit;					% initialize MATALB

%Simulation of proportional 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 k=[1 2 5],
   C=k;
   [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-');
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 20 0 1.725]); 
%xlabel('x'); 
ylabel('y')

arcarrow([11 0.4], [15 1.2], -20);
amtext(15, 1.35, 'kp');

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-');
set(pl,'Linewidth', AM_data_linewidth)
amaxis([0 20 -2 5]); 
xlabel('x');ylabel('u');

arcarrow([0.5 0.5], [2.5 2.8], -10);
amtext(2.8, 3.4, 'kp');

amprint('pcon.eps');
