control systems lab report
% Lab 2
%% Experiment 1 a
clear all;
clc;
close all;
numg = 10*poly([-7]);
deng = poly([0 -4 -8 -12]);
G = tf(numg,deng);
numh = poly([-10]);
denh = poly([-5 -15 -20]);
H = tf(numh,denh);
Ge = feedback(G,(H-1));
disp('Checking Stability:')
Ge = tf(Ge)
T = feedback(Ge,1);
disp('Step Input of 30u(t)')
Kp = dcgain(Ge)
ess = 30/(1+Kp);
Zeros = zero(Ge);
Poles = pole(Ge);
disp('Ramp Input of 30tu(t)')
numsGe = 10*poly([Zeros]);
numsGe = conv([1 0],numsGe);
densGe = poly([Poles]);
sG = tf(numsGe,densGe);
sG = minreal(sG);
Kv = dcgain(sG)
ess = 30/Kv
disp('Parabolic Input of 30t^2(t)')
nums2Ge = 10*poly([Zeros]);
nums2Ge = conv([1 0 0],numsGe);
dens2Ge = poly([Poles]);
s2G = tf(nums2Ge,dens2Ge);
s2G = minreal(s2G);
Ka = dcgain(s2G)
ess = 30/Ka
%% Experiment 1b
clear all;
clc;
close all;
numG1 = poly([-7]);
denG1 = poly([0 -4 -8 -12]);
G1 = tf(numG1,denG1); % Creating the transfer function G1
numG2 = 5*poly([-9 -13]); % Numerator of Ge
denG2 = poly([-10 -32 -64]); % Denominator of Ge
G2 = tf(numG2,denG2); % Creating the transfer function
G2 = feedback(G2,10); %Checking Stability
Ge1 = G1*G2 %Multiplying the transfer function by the feedback
numH = 1; % Numerator of h
denH = poly([-3]); % Denominator of h
H = tf(numH,denH); % Creating the transfer function H
Ge = feedback(Ge1,H) %Checking Stability
Zeros = zero(Ge) % finding the roots of the numerator
Poles = pole(Ge) % finding the roots of the denominator
disp('Step input of 30u(t)'); %display step Input of 30tu(t)
Kp = dcgain(Ge) %Dc gain of function Ge
ess = 30/(1+Kp) %Steady state error formula
disp('Ramp input of 30tu(t)'); %display ramp input 30tu(t)
numsGe = 5*poly([Zeros]); %Numerator of Ge
numsGe = conv([1 0],numsGe); %New Numerator of Ge
densGe = poly([Poles]); %Denominator of Ge
sG = tf(numsGe,densGe); %Transfer function of numerator and denominator Ge
sG = minreal(sG); % pole cancelation of the poles outside the range
Kv = dcgain(sG) %Dc gain of function Ge
ess = 30/Kv %Steady state error formula for Kv
disp('Parabolic Input of 30t^2(t)') %Displays Parabolic input of 30t^2(t)
nums2Ge = 5*poly([Zeros]);
nums2Ge = conv([1 0 0],numsGe);
dens2Ge = poly([Poles]);
s2G = tf(nums2Ge,dens2Ge);
s2G = minreal(s2G);
Ka = dcgain(s2G)
ess = 30/Ka
%% Experiment 2A)a
clc; %Clear Screen
close all; %Close all the opened programs within matlab
clear all; %Clears all values
Kp=2; %Setting variable Kp to 2
Km=19.513; %Setting variable Km to 19.513
Ko=0.796; %Setting variable Kp to 0.796
t=0.1; %Setting variable Kp to 0.1
var = 10*Kp*Km*Ko; %Setting variable var to multiply 10*Kp*Km*Ko
num = var; %Setting variable num to var
den = [1,10,var]; %Setting variable Kp to 1 10 and variable var
G = tf(num,den) %Transfer function num divided by den
s = tf([1 0],1); %Transfer function of values shown
'Step' %For step function
Kp = dcgain(G) %Setting variable Kp to the gain G (feedback)
estep = 1/(1+Kp) %Applying the step function formula for error
'Ramp' %For step function
Kv = dcgain(s*G) %Setting variable Kv to the gain G times s
eramp = 1/Kv %Applying the ramp function formula for error
'Parabolic' %For step function
Ka = dcgain((s^2)*G) %Setting variable Ka to the gain G times s^2
epara = 1/Ka %Applying the parabolic function formula for error
if ((Kp~=0) && (Kp~=inf)) %If Kp does not=0, and kp is not infinite
fprintf('System type 0 \n'); %Displays “system type 0”
elseif ((Kv~=0) && (Kv~=inf)) %If Kv does not=0, and kv is not infinite
fprintf('system type 1 \n'); %Displays “system type 1”
else %Or else move to next line
fprintf('System type 2 \n'); %Displays “system type 2”
end
%% Experiment 2B
clc; %Clear Screen
close all; %Close all the opened programs within matlab
clear all; %Clears all values
Kp=2; %Setting variable Kp to 2
Km=19.513; %Setting variable Km to 19.513
Ko=0.796; %Setting variable Kp to 0.796
t=0.1; %Setting variable Kp to 0.1
var = 10*Kp*Km*Ko; %Setting variable var to multiply 10*Kp*Km*Ko
num = var; %Setting variable num to var
den = [1,10,0]; %Setting variable Kp to 1 10 0
G = tf(num,den) %Transfer function num divided by den
s = tf([1 0],1); %Transfer function of values shown
'Step' %For step function
Kp = dcgain(G) %Setting variable Kp to the gain G (feedback)
estep = 1/(1+Kp) %Applying the step function formula for error
'Ramp' %For step function
Kv = dcgain(s*G) %Setting variable Kv to the gain G times s
eramp = 1/Kv %Applying the ramp function formula for error
'Parabolic' %For step function
Ka = dcgain((s^2)*G) %Setting variable Ka to the gain G times s^2
epara = 1/Ka %Applying the parabolic function formula for error
if ((Kp~=0) && (Kp~=inf)) %If Kp does not=0, and kp is not infinite
fprintf('System type 0 \n'); %Displays “system type 0”
elseif ((Kv~=0) && (Kv~=inf)) %If Kv does not=0, and kv is not infinite
fprintf('system type 1 \n'); %Displays “system type 1”
else %Or else move to next line
fprintf('System type 2 \n'); %Displays “system type 2”
end