%Response of a proportional controller to a step change 
%to set point for a first-order process. You can change
%the controller gain kc to see how the offset changes by
%changing the kc value.
close all
clear all
clc

M=3;

kp=2;
tau=1;
kc=2.0;

K1=kc*kp/(1+kc*kp);
TAU=tau/(1+kc*kp);
t=0:.01:3;
ysp=M*ones(1,length(t));


y=K1*M*(1-exp(-t/TAU));
subplot(2,1,1)
plot(t,y,t,ysp,'--','LineWidth',3)
xlabel('t','FontSize',16)
ylabel('y','FontSize',16)
legend('y','y_{sp}')
axis([0 t(end) 0 1.1*M])
set(gca,'FontSize',16)

subplot(2,1,2)
u=kc*(ysp-y);
plot(t,u,'r','LineWidth',3)
xlabel('t','FontSize',16)
ylabel('u','FontSize',16)
set(gca,'FontSize',16)