Lead-Lag Compensator
% After simulating on Simulink, you'll get an error. Let's say you want to
% get that number down to 5%, for instance. That error can only be achieved
% adding a Lag Compensator.
%---------- >>LAG COMPENSATOR<< ----------%
% Calculate the gain using the steady state error expression
ess = 0.05;
syms k;
eqn = ess == 1/(1+(kp_system*kp_lead*k));
kp_lag = vpasolve(eqn, k);
kp_lag = double(kp_lag);
kp_lag = round(kp_lag,1);
% Calculate the compensator expression
syms a_2;
eqn = (1-a_2)/(1-0.99) == kp_lag;
a_2 = vpasolve(eqn, a_2);
a_2 = double(a_2);
%---------- ZPK ----------%
zeros = [zero, a_2];
poles = [pole, 0.99];
C2z = zpk(zeros, poles, gain, T);