HW-3 1
HW-3 1
HW-3 Page 1
Problem#1
HW-3 Page 2
HW-3 Page 3
HW-3 Page 4
HW-3 Page 5
Problem#1 Code
clc;
close all;
% Define the transfer function P(s) = 100 / (0.5s + 1)
numP = [100];
denP = [0.5 1];
P = tf(numP, denP);
% Define the transfer function C2(s) and C3(s)
s = tf('s');
C2 = (s + 1) / s * ((s/(100*pi) + 1)^2 / (s^2/(100*pi)^2 + 1));
C3 = (s/487 +1)/(s/4900 +1);
% Define the open-loop system: C2(s)C3(s)P(s)
C2C3P = C2 * P*C3;
% Define the closed-loop system with unity feedback
closed_loop_sys = feedback(C2C3P, 1);
% Generate time vector for the step response
t = 0:0.01:10; % Adjust the time range as needed
% Get the closed-loop step response
[response, time] = step(closed_loop_sys, t);
% Plot the unit step and the closed-loop step response
figure;
hold on;
% Plot the unit step input
plot(t, ones(size(t)), 'b--', 'LineWidth', 1.5); % Blue dashed line for unit step
% Plot the closed-loop step response
plot(time, response, 'r', 'LineWidth', 1.5); % Red line for closed-loop step response
% Add grid, labels, and legend
grid on;
title('Unit Step Input vs. Closed-Loop Step Response');
xlabel('Time (seconds)');
ylabel('Amplitude');
legend('Unit Step Input', 'Closed-Loop Step Response');
hold off;
% Display step response information
info = stepinfo(closed_loop_sys);
disp(['Rise Time (T_r): ', num2str(info.RiseTime), ' seconds']);
disp(['Peak Time (T_p): ', num2str(info.PeakTime), ' seconds']);
disp(['Percentage Overshoot (M_p): ', num2str(info.Overshoot), ' %']);
% Bode plot for both C2C3P and P
figure;
hold on;
% Plot the Bode plot for P(s)
bode(P, 'b'); % Plot P(s) in blue
hold on;
% Plot the Bode plot for C2C3P(s)
bode(C2C3P, 'r'); % Plot C2C3P(s) in red
% Add grid and legend
grid on;
legend('P(s) = 100/(0.5s + 1)', 'C2C3P(s) = C2(s)C3(s) * P(s)');
hold off;
% Compute and display stability margins for C2C3P(s)
[GM_C2C3P, PM_C2C3P, Wcg_C2C3P, Wcp_C2C3P] = margin(C2C3P);
disp('For C2C3P(s):');
disp(['Gain Margin: ', num2str(20*log10(GM_C2C3P)), ' dB']);
disp(['Phase Margin: ', num2str(PM_C2C3P), ' degrees']);
disp(['Gain Crossover Frequency: ', num2str(Wcp_C2C3P), ' rad/s']);
disp(['Phase Crossover Frequency: ', num2str(Wcg_C2C3P), ' rad/s']);
% Compute and display stability margins for P(s) if needed
[GM_P, PM_P, Wcg_P, Wcp_P] = margin(P);
disp('For P(s):');
disp(['Gain Margin: ', num2str(20*log10(GM_P)), ' dB']);
disp(['Phase Margin: ', num2str(PM_P), ' degrees']);
disp(['Gain Crossover Frequency: ', num2str(Wcp_P), ' rad/s']);
disp(['Phase Crossover Frequency: ', num2str(Wcg_P), ' rad/s']);
% Closed-loop transfer function for disturbance rejection
G2 = P / (1 + C2C3P);
% Define the time vector for simulation
HW-3 Page 6
% Define the time vector for simulation
t = 0:0.001:1;
% Define the disturbance signal d(t) = sin(5t)
disturbance = sin(100*pi * t);
% Obtain the response of the system to the disturbance using lsim
[yDisturbance, tOut] = lsim(G2, disturbance, t);
% Plot the disturbance response
figure;
plot(tOut, yDisturbance, 'r--', t, disturbance, 'b');
title('Response of Closed-Loop System to Disturbance d(t) = sin(5t)');
xlabel('Time (seconds)');
ylabel('Amplitude');
legend('System Output', 'Disturbance Input (sin(5t))');
grid on;
HW-3 Page 7
Problem#2
HW-3 Page 8
HW-3 Page 9
HW-3 Page 10
Problem#2 Code
clc;
close all;
s=tf('s');
G= 100/ ((s + 1) * (s + 2));
G1= (s+1)*(s+2)/100;
C=(s/10 +1)^2/(s^2/100 +1);
C1= (s/9.9 +1)/(s/100 +1);
FF=G*G1;
L=G*C*C1;
Td=1/(1+L);
figure;
margin(L)
grid on
t = 0:0.01:15;
disturbance= sin(10*t);
ref= sin(5*t);
[y, t_out] = lsim(Td, disturbance, t);
figure;
plot(t, disturbance, 'r--', 'DisplayName', 'input disturbance of 10 rad/s');
hold on;
plot(t_out, y, 'b', 'DisplayName', 'System Output');
xlabel('Time (s)');
ylabel('Amplitude');
legend;
title('output disturbance rejection of 10rad/sec');
grid on;
[y1, t_out1] = lsim(FF, ref, t);
figure;
plot(t, ref, 'r--','LineWidth',1.5, 'DisplayName','input reference tracking of 5rad/sec');
hold on;
plot(t_out1, y1, 'b', 'DisplayName', 'System Output');
xlabel('Time (s)');
ylabel('Amplitude');
legend;
title('input reference tracking');
grid on;
HW-3 Page 11
Problem#3
HW-3 Page 12
HW-3 Page 13
HW-3 Page 14
HW-3 Page 15
Problem#4
HW-3 Page 16
HW-3 Page 17
HW-3 Page 18
Problem#4 Code
clc;
close all;
% Define the transfer function P(s) = 1 / [s(s + 5)(s + 7)]
s = tf('s');
P = 1 / (s * (s + 5) * (s + 7));
% Define the transfer function C(s) = 138.82 * (s + 8.88) / (s + 20)
C = 138.82 * (s + 8.88) / (s + 20);
% Open-loop system C(s)P(s)
CP = C * P;
% Plot the root locus of P(s) (blue)
figure;
rlocus(P, 'b'); % Blue for P(s)
hold on;
% Plot the root locus of C(s)P(s) (red)
rlocus(CP, 'r'); % Red for C(s)P(s)
% Highlight the points -2 + j2 and -2 - j2
plot(-2, 2, 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'y'); % Yellow filled circle for -2 + j2
plot(-2, -2, 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'y'); % Yellow filled circle for -2 - j2
% Add grid, labels, and title
grid on;
title('Root Locus of P(s) and C(s)P(s)');
legend('Root Locus of P(s)', 'Root Locus of C(s)P(s)', 'Point (-2 + j2)', 'Point (-2 - j2)', 'Location', 'Best');
xlabel('Real Axis');
ylabel('Imaginary Axis');
hold off;
HW-3 Page 19
Problem#5 (a)
HW-3 Page 20
HW-3 Page 21
HW-3 Page 22
HW-3 Page 23
HW-3 Page 24
HW-3 Page 25
HW-3 Page 26
Problem#5 (a) Code
clc;
close all;
s=tf('s');
G = 3598172.16/((s + 35.2)*(s + 264)*(s + 387.2));
C =2099373.28*(s^2 + 271.492*s + 113031.8178)*(s +300)/((s)*(s+74852.9603)^2);
F = 33909545.34/((s^2 + 271.492*s + 113031.8178)*(s +300));
L=C*G;
T_step = feedback(L, 1);
t = 0:0.000001:0.2;
figure;
[yStep] = lsim(T_step, ones(size(t)), t);
plot(t, yStep, 'b');
grid on;
title('Step Response of the Closed-Loop System');
K_min = 8.8;
K_nominal = 13.2;
K_1 = 15;
K_2 = 22;
K_max = 39.6;
K_values = [K_min, K_nominal, K_1, K_2, K_max];
figure;
rlocus(L);
title('Root Locus with Dominant Pole Variation');
hold on;
% Specify the desired pole location (a + jb)
a = -132;
b = 308;
desired_pole = a + 1i*b;
% Find the gain at the specified pole location
[K, poles] = rlocfind(L, desired_pole);
% Plot the specified pole location on the root locus
plot(real(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(desired_pole), imag(desired_pole));
fprintf('Corresponding open-loop gain (K): %.4f\n', K);
a = -132;
b = 308;
dpc = a - 1i*b;
% Find the gain at the specified pole location
[K1, poles1] = rlocfind(L, dpc);
% Plot the specified pole location on the root locus
plot(real(dpc), imag(dpc), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(dpc), imag(dpc), sprintf(' %d-j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(dpc), imag(dpc));
fprintf('Corresponding open-loop gain (K): %.4f\n', K1);
hold off;
%% 3. Step Response of the 2DOF Control System for Selected K Values
figure;
hold on;
for i = 1:length(K_values)
Loop=K_values(i)*G*C;
ClosedLoop_2DOF = F*feedback(Loop, 1);
[y, t] = step(ClosedLoop_2DOF); % Step response
plot(t, y, 'LineWidth', 1.5); % Plot step response
end
legend(['K = ', num2str(K_min)], ['K = ', num2str(K_nominal)], ['K = ', num2str(K_1)], ['K = ',
num2str(K_2)], ['K = ', num2str(K_max)]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Step Response of 2DOF Control System for K = 0.5, 1, 2, 3, 4');
grid on;
hold off;
% Define the fixed dominant pole location
fixed_pole = -132 + 308i * 1; % Dominant pole at -96 + j224
HW-3 Page 27
fixed_pole = -132 + 308i * 1; % Dominant pole at -96 + j224
%% 1. Plot the Root Locus and Track Pole Movement for Selected K Values
figure;
rlocus(L); % Plot root locus of the plant G(s)
title('Root Locus with Dominant Pole Variation for K = 0.5, 1, 2, 3, 4');
hold on;
% Initialize array to store pole locations for selected K values
poles_at_K = zeros(length(K_values), 1);
% Find and plot dominant poles for the selected K values
for i = 1:length(K_values)
poles = rlocus(L, K_values(i)); % Find poles for gain K
% Find the pole closest to the fixed pole (-1 + j1)
[~, closest_index] = min(abs(poles - fixed_pole));
poles_at_K(i) = poles(closest_index); % Store closest pole
plot(real(poles(closest_index)), imag(poles(closest_index)), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
end
%% 2. Plot the K Variation and Calculate the Distance Between Pole Positions
for i = 1:length(K_values) - 1
% Plot the line connecting poles between different K values
plot([real(poles_at_K(i)), real(poles_at_K(i+1))], [imag(poles_at_K(i)), imag(poles_at_K(i+1))], 'g--',
'LineWidth', 2);
HW-3 Page 28
Problem#5 (b)
HW-3 Page 29
HW-3 Page 30
HW-3 Page 31
HW-3 Page 32
HW-3 Page 33
HW-3 Page 34
Problem#5 (b) Code
clc;
close all;
s=tf('s');
P_min = 4.4;
P_nominal = 35.2;
P_1 = 40;
P_2 = 60;
P_max = 110;
P_values = [P_min, P_nominal, P_1, P_2, P_max];
G = (3598172.16*13.2) /((s + 264)*(s + 387.2));
C = 5218.2098 * (s^2 + 290.7368*s + 115074.5282) * (s + 300) / (s * (s + 7116.6534)^2);
F = 34522358.47 / ((s^2 + 290.7368*s + 115074.5282) * (s + 300));
L = (1/(s + P_nominal))*G*C;
T_step = feedback(L, 1);
t = 0:0.000001:0.2;
figure;
[yStep] = lsim(T_step, ones(size(t)), t);
plot(t, yStep, 'b');
grid on;
title('Step Response of the Closed-Loop System');
figure;
rlocus(L);
hold on;
title('Root Locus with Dominant Pole Variation');
% Specify the desired pole location (a + jb)
a = -132;
b = 308;
desired_pole = a + 1i*b;
% Find the gain at the specified pole location
[K, poles] = rlocfind(L, desired_pole);
% Plot the specified pole location on the root locus
plot(real(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
% % Display the pole location and the corresponding gain
% fprintf('Specified pole location: %.4f + %.4fj\n', real(desired_pole), imag(desired_pole));
% fprintf('Corresponding open-loop gain (K): %.4f\n', K);
a = -132;
b = 308;
dpc = a - 1i*b;
% Find the gain at the specified pole location
[K1, poles1] = rlocfind(L, dpc);
% Plot the specified pole location on the root locus
plot(real(dpc), imag(dpc), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(dpc), imag(dpc), sprintf(' %d-j%d',a,b), 'FontSize', 10, 'Color', 'red');
hold off;
% % Display the pole location and the corresponding gain
% fprintf('Specified pole location: %.4f + %.4fj\n', real(dpc), imag(dpc));
% fprintf('Corresponding open-loop gain (K): %.4f\n', K1);
% 3. Step Response of the 2DOF Control System for Selected K Values
figure;
for i = 1:length(P_values)
Loop=(1/(s + P_values(i)))*G*C;
ClosedLoop_2DOF = F*feedback(Loop, 1);
hold on;
[y, t] = step(ClosedLoop_2DOF); % Step response
plot(t, y, 'LineWidth', 1.5); % Plot step response
end
legend(['P = ', num2str(P_min)], ['P = ', num2str(P_nominal)], ['P = ', num2str(P_1)], ['P = ',
num2str(P_2)], ['P = ', num2str(P_max)]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Step Response of 2DOF Control System for P = 8.8, 13.2, 15, 22, 39.6');
grid on;
hold off;
% Loop to vary P_values and plot on the same figure
figure;
HW-3 Page 35
figure;
for i = 1:length(P_values)
current_sys = (1/(s + P_values(i)))*G*C; % Update the pole P_values
rlocus(current_sys); % Plot root locus for the current value of P_values
hold on;
end
% Add title and labels
% legend(['P = ', num2str(P_min)], ['P = ', num2str(P_nominal)], ['P = ', num2str(P_1)], ['P = ',
num2str(P_2)], ['P = ', num2str(P_max)]);
title('Root Locus with Varying P_values from 4.4 to 110');
xlabel('Real Axis');
ylabel('Imaginary Axis');
grid on;
hold off;
% Define the fixed dominant pole location
fixed_pole = -132 + 308i * 1; % Dominant pole at -96 + j224
% 1. Plot the Root Locus and Track Pole Movement for Selected P Values
figure;
rlocus(L); % Plot root locus of the plant G(s)
title('Root Locus with Dominant Pole Variation for P = 8.8, 13.2, 15, 22, 39.6');
hold on;
% Initialize array to store pole locations for selected K values
poles_at_K = zeros(length(P_values), 1);
% Find and plot dominant poles for the selected K values
for i = 1:length(P_values)
sys = (1/(s + P_values(i)))*G*C;
rlocus(sys)
poles = rlocus(sys, K); % Find poles for gain K
% Find the pole closest to the fixed pole (-1 + j1)
[~, closest_index] = min(abs(poles - fixed_pole));
poles_at_K(i) = poles(closest_index); % Store closest pole
plot(real(poles(closest_index)), imag(poles(closest_index)), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
end
% 2. Plot the P Variation and Calculate the Distance Between Pole Positions
for i = 1:length(P_values) - 1
% Plot the line connecting poles between different P values
plot([real(poles_at_K(i)), real(poles_at_K(i+1))], [imag(poles_at_K(i)), imag(poles_at_K(i+1))], 'g--',
'LineWidth', 2);
HW-3 Page 36
Problem#5 (c)
HW-3 Page 37
HW-3 Page 38
HW-3 Page 39
HW-3 Page 40
HW-3 Page 41
HW-3 Page 42
Problem#5 (c) Code
clc;
close all;
s=tf('s');
K_min = 8.8;
K_nominal = 13.2;
K_1 = 20;
K_2 = 30;
K_max = 39.6;
K_values = [K_min, K_nominal, K_1, K_2, K_max];
P_min = 4.4;
P_nominal = 35.2;
P_1 = 50;
P_2 = 80;
P_max = 110;
P_values = [P_min, P_nominal, P_1, P_2, P_max];
G = 3598172.16 /((s + 264)*(s + 387.2));
C = 5599318.831 * (s^2 + 269.6306*s + 112844.7320) * (s + 300) / (s * (s + 104334.3409)^2);
F = 33853419.6 / ((s^2 + 269.6306*s + 112844.7320) * (s + 300));
L = K_nominal*(1/(s + P_nominal))*G*C;
T_step = feedback(L, 1);
t = 0:0.0001:0.1;
figure;
u = stepfun(t, 0);
[yStep] = lsim(T_step, u , t);
plot(t, yStep, 'b');
grid on;
title('Step Response of the Closed-Loop System');
figure;
rlocus(L);
hold on;
title('Root Locus with Dominant Pole Variation');
% Specify the desired pole location (a + jb)
a = -132;
b = 308;
desired_pole = a + 1i*b;
% Find the gain at the specified pole location
[K, poles_K] = rlocfind(L, desired_pole);
% Plot the specified pole location on the root locus
plot(real(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
% % Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(desired_pole), imag(desired_pole));
fprintf('Corresponding open-loop gain (K): %.4f\n', K);
a = -132;
b = 308;
dpc = a - 1i*b;
% Find the gain at the specified pole location
[K1, poles1] = rlocfind(L, dpc);
% Plot the specified pole location on the root locus
plot(real(dpc), imag(dpc), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(dpc), imag(dpc), sprintf(' %d-j%d',a,b), 'FontSize', 10, 'Color', 'red');
hold off;
% % Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(dpc), imag(dpc));
fprintf('Corresponding open-loop gain (K): %.4f\n', K1);
% 1. Step Response of the 2DOF Control System for Selected K Values
figure;
for j = 1:length(K_values)
for i = 1:length(P_values)
Loop=K_values(j)*(1/(s + P_values(i)))*G*C;
ClosedLoop_2DOF = F*feedback(Loop, 1);
hold on;
[y, t] = step(ClosedLoop_2DOF); % Step response
plot(t, y, 'LineWidth', 1.5); % Plot step response
end
end
HW-3 Page 43
end
legend(['P = ', num2str(P_min)], ['P = ', num2str(P_nominal)], ['P = ', num2str(P_1)], ['P = ',
num2str(P_2)], ['P = ', num2str(P_max)]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Step Response of 2DOF Control System for P = 4.4, 35.2, 40, 60, 110');
grid on;
hold off;
% Loop to vary P_values and plot on the same figure
figure;
for j = 1:length(K_values)
for i = 1:length(P_values)
current_sys = K_values(j)*(1/(s + P_values(i)))*G*C; % Update the pole P_values
rlocus(current_sys); % Plot root locus for the current value of P_values
hold on;
end
end
% Add title and labels
legend(['P = ', num2str(P_min)], ['P = ', num2str(P_nominal)], ['P = ', num2str(P_1)], ['P = ',
num2str(P_2)], ['P = ', num2str(P_max)]);
title('Root Locus with Varying P from 4.4 to 110');
xlabel('Real Axis');
ylabel('Imaginary Axis');
grid on;
hold off;
% Define the fixed dominant pole location
fixed_pole = -132 +308i; % Dominant pole at -96 + j224
% 1. Plot the Root Locus and Track Pole Movement for Selected P Values
figure;
rlocus(L); % Plot root locus of the plant G(s)
title('Root Locus with Dominant Pole Variation for P = 4.4, 35.2, 40, 60, 110');
hold on;
% Initialize array to store pole locations for selected K values
poles_at_K = zeros(length(K_values), 1);
% Find and plot dominant poles for the selected K values
% for j = 1:length(K_values)
% poles_K = rlocus(L, K_values(j)); % Find poles for gain K
% % Find the pole closest to the fixed pole (-1 + j1)
% [~, closest_index_K] = min(abs(poles_K - fixed_pole));
% poles_at_K(j) = poles_K(closest_index_K); % Store closest pole
% plot(real(poles_K(closest_index_K)), imag(poles_K(closest_index_K)), 'ro', 'MarkerSize', 8,
'LineWidth', 2);
% end
%% 2. Plot the K Variation and Calculate the Distance Between Pole Positions
% for j = 1:length(K_values) - 1
% % Plot the line connecting poles between different K values
% plot([real(poles_at_K(j)), real(poles_at_K(j+1))], [imag(poles_at_K(j)), imag(poles_at_K(j+1))],
'g--', 'LineWidth', 2);
%
% % Calculate the distance between poles
% distance_K = abs(poles_at_K(j+1) - poles_at_K(j));
%
% % Display the distance on the plot
% mid_point_real_K = (real(poles_at_K(j)) + real(poles_at_K(j+1))) / 2;
% mid_point_imag = (imag(poles_at_K(j)) + imag(poles_at_K(j+1))) / 2;
% text(mid_point_real_K, mid_point_imag, sprintf('%.2f', distance_K), 'FontSize', 10, 'Color', 'b');
% end
% Initialize array to store pole locations for selected K values
poles_at_P = zeros(length(P_values), 1);
% 2. Find and plot dominant poles for the selected P values
for j = 1:length(K_values)
for i = 1:length(P_values)
sys = K_values(j)*(1/(s + P_values(i)))*G*C;
poles_K = rlocus(sys, K_values(j)); % Find poles for gain K
% Find the pole closest to the fixed pole (-1 + j1)
rlocus(sys)
poles_P = rlocus(sys, K);
[~, closest_index_K] = min(abs(poles_K - fixed_pole));
poles_at_K(j) = poles_K(closest_index_K); % Store closest pole
HW-3 Page 44
poles_at_K(j) = poles_K(closest_index_K); % Store closest pole
plot(real(poles_K(closest_index_K)), imag(poles_K(closest_index_K)), 'ro', 'MarkerSize', 8,
'LineWidth', 2);
sys = K_values(i)*(1/(s + P_values(i)))*G*C;
[~, closest_index_P] = min(abs(poles_P - fixed_pole));
poles_at_P(i) = poles_P(closest_index_P); % Store closest pole
plot(real(poles_P(closest_index_P)), imag(poles_P(closest_index_P)), 'ro', 'MarkerSize', 8,
'LineWidth', 2);
end
end
% 2. Plot the P Variation and Calculate the Distance Between Pole Positions
for j = 1:length(K_values) - 1
for i = 1:length(P_values) - 1
HW-3 Page 45
Problem#6
HW-3 Page 46
HW-3 Page 47
HW-3 Page 48
HW-3 Page 49
HW-3 Page 50
HW-3 Page 51
Problem#6 Code
clc;
clear;
close all;
s = tf('s');
C = 11.06 * (s + 1.053) / s;
F = 1.053 / (s + 1.053);
p_nominal = -5 + 1j; % nominal value of p
p_variation = [-7, -3]; % range of variation for the real part of p
% Plant transfer function for the nominal system
P_nom = (s^2 + 12*s + 40) / ((s - p_nominal)*(s - conj(p_nominal)));
for i = 1:length(p_variation)
p_real = p_variation(i);
p_var = -3 + imag(p_nominal) * 1j;
P_var = (s^2 + 12*s + 40) / ((s - p_var)*(s - conj(p_var)));
L=C*P_var;
desired_pole = -1;
figure;
hold on;
rlocus(L);
grid on;
plot(dreal(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
hold off;
end
HW-3 Page 52
Problem#7
HW-3 Page 53
HW-3 Page 54
HW-3 Page 55
HW-3 Page 56
Problem#7 Code
clc;
close all;
s=tf('s');
G=1/(s^2+1);
C=(2764.368/s)*((s^2+1.892*s+1.857277)/((s+100)));
F=1.857277/(s^2+1.892*s+1.857277);
L=C*G;
K_min = 0.5;
K_nominal = 1;
K_max = 4;
K_values = [K_min, K_nominal, K_max];
figure;
rlocus(L);
title('Root Locus with Dominant Pole Variation');
hold on;
% Specify the desired pole location (a + jb)
a = -1;
b = 1;
desired_pole = a + 1i*b;
% Find the gain at the specified pole location
[K, poles] = rlocfind(L, desired_pole);
% Plot the specified pole location on the root locus
plot(real(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(desired_pole), imag(desired_pole));
fprintf('Corresponding open-loop gain (K): %.4f\n', K);
a = -1;
b = 1;
dpc = a - 1i*b;
% Find the gain at the specified pole location
[K1, poles1] = rlocfind(L, dpc);
% Plot the specified pole location on the root locus
plot(real(dpc), imag(dpc), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(dpc), imag(dpc), sprintf(' %d-j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(dpc), imag(dpc));
fprintf('Corresponding open-loop gain (K): %.4f\n', K1);
hold off;
%% 3. Step Response of the 2DOF Control System for Selected K Values
figure;
hold on;
for i = 1:length(K_values)
Loop=K_values(i)*G*C;
ClosedLoop_2DOF = F*feedback(Loop, 1);
[y, t] = step(ClosedLoop_2DOF); % Step response
plot(t, y, 'LineWidth', 1.5); % Plot step response
end
legend(['K = ', num2str(K_min)], ['K = ', num2str(K_nominal)], ['K = ', num2str(K_max)]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Step Response of 2DOF Control System for K = 0.5, 1, 10');
grid on;
hold off;
% Define the fixed dominant pole location
fixed_pole = -1 + 1i * 1; % Dominant pole at -5 + j5
%% 1. Plot the Root Locus and Track Pole Movement for Selected K Values
figure;
rlocus(L); % Plot root locus of the plant G(s)
title('Root Locus with Dominant Pole Variation for K = 0.5, 1, 5');
hold on;
% Initialize array to store pole locations for selected K values
poles_at_K = zeros(length(K_values), 1);
% Find and plot dominant poles for the selected K values
for i = 1:length(K_values)
poles = rlocus(L, K_values(i)); % Find poles for gain K
HW-3 Page 57
poles = rlocus(L, K_values(i)); % Find poles for gain K
% Find the pole closest to the fixed pole (-5 + j5)
[~, closest_index] = min(abs(poles - fixed_pole));
poles_at_K(i) = poles(closest_index); % Store closest pole
plot(real(poles(closest_index)), imag(poles(closest_index)), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
end
%% 2. Plot the Variation and Calculate the Distance Between Pole Positions
for i = 1:length(K_values) - 1
% Plot the line connecting poles between different K values
plot([real(poles_at_K(i)), real(poles_at_K(i+1))], [imag(poles_at_K(i)), imag(poles_at_K(i+1))], 'g--',
'LineWidth', 2);
HW-3 Page 58
Problem#8
HW-3 Page 59
HW-3 Page 60
HW-3 Page 61
HW-3 Page 62
Problem#8 Code
clc;
close all;
s=tf('s');
G=1/((s)*(s+5));
C=343666.8657*((s^2)+(6.016*s)+18.308)/((s+80)^2);
F=18.308/((s^2)+(6.016*s)+18.308);
L=C*G;
K_min = 0.2;
K_nominal = 1;
K_max = 2;
K_values = [K_min, K_nominal, K_max];
figure;
rlocus(L);
title('Root Locus with Dominant Pole Variation');
hold on;
% Specify the desired pole location (a + jb)
a = -3;
b = 3;
desired_pole = a + 1i*b;
% Find the gain at the specified pole location
[K, poles] = rlocfind(L, desired_pole);
% Plot the specified pole location on the root locus
plot(real(desired_pole), imag(desired_pole), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(desired_pole), imag(desired_pole), sprintf(' %d+j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(desired_pole), imag(desired_pole));
fprintf('Corresponding open-loop gain (K): %.4f\n', K);
a = -3;
b = 3;
dpc = a - 1i*b;
% Find the gain at the specified pole location
[K1, poles1] = rlocfind(L, dpc);
% Plot the specified pole location on the root locus
plot(real(dpc), imag(dpc), 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(real(dpc), imag(dpc), sprintf(' %d-j%d',a,b), 'FontSize', 10, 'Color', 'red');
% Display the pole location and the corresponding gain
fprintf('Specified pole location: %.4f + %.4fj\n', real(dpc), imag(dpc));
fprintf('Corresponding open-loop gain (K): %.4f\n', K1);
hold off;
%% 3. Step Response of the 2DOF Control System for Selected K Values
figure;
hold on;
for i = 1:length(K_values)
Loop=K_values(i)*G*C;
ClosedLoop_2DOF = F*feedback(Loop, 1);
[y, t] = step(ClosedLoop_2DOF); % Step response
plot(t, y, 'LineWidth', 1.5); % Plot step response
end
legend(['K = ', num2str(K_min)], ['K = ', num2str(K_nominal)], ['K = ', num2str(K_max)]);
xlabel('Time (s)');
ylabel('Amplitude');
title('Step Response of 2DOF Control System for K = 0.2, 1, 2');
grid on;
hold off;
% Define the fixed dominant pole location
fixed_pole = -4 + 1i * 4; % Dominant pole at -4 + j4
%% 1. Plot the Root Locus and Track Pole Movement for Selected K Values
figure;
rlocus(L); % Plot root locus of the plant G(s)
title('Root Locus with Dominant Pole Variation for K = 0.2, 1, 2');
hold on;
% Initialize array to store pole locations for selected K values
poles_at_K = zeros(length(K_values), 1);
% Find and plot dominant poles for the selected K values
for i = 1:length(K_values)
poles = rlocus(L, K_values(i)); % Find poles for gain K
HW-3 Page 63
poles = rlocus(L, K_values(i)); % Find poles for gain K
% Find the pole closest to the fixed pole (-4 + j4)
[~, closest_index] = min(abs(poles - fixed_pole));
poles_at_K(i) = poles(closest_index); % Store closest pole
plot(real(poles(closest_index)), imag(poles(closest_index)), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
end
%% 2. Plot the Variation and Calculate the Distance Between Pole Positions
for i = 1:length(K_values) - 1
% Plot the line connecting poles between different K values
plot([real(poles_at_K(i)), real(poles_at_K(i+1))], [imag(poles_at_K(i)), imag(poles_at_K(i+1))], 'g--',
'LineWidth', 2);
HW-3 Page 64