Help on plot 3 roots for each variable and connecting them

4 views (last 30 days)
I'm trying to plot the roots coming out of the this code but after I Run the code, no graph shows up. I know that for each variable K_p_no, there's 3 roots because the pol variable shows up in the Workspace with 3 roots in a single cell. How can I find the roots of the equation and plot them all in the same graph? If possible, also connect them. This is for a PID controller but without the ID, if it helps in any way.
clc; clear all; close all;
n = 10;
K_p_neg_inf = -1000;
K_p_pos_inf = 1000;
K_p_no = K_p_neg_inf:n:K_p_pos_inf;
for i=1:length(K_p_no);
ChEq{i} = [K_p_no(i)*50 K_p_no(i)*100 1 K_p_no(i)*60]; %characteris eqn (K_p*50*s^2 + K_p*100*s + s^2 + K_p*60) of the T_s, set =0 to find the poles in the s-plane
pol{i} = roots(ChEq{i}); %poles on s-plane
plot(real(poles), imag(poles), 'rx')
xlabel('Real Axis (seconds^-1)');
ylabel('Imaginary Axis (seconds^-1)')
grid on
end

Accepted Answer

Star Strider
Star Strider on 26 Jan 2021
See if this slightly edited version of your code does what you want:
n = 10;
K_p_neg_inf = -1000;
K_p_pos_inf = 1000;
K_p_no = K_p_neg_inf:n:K_p_pos_inf;
figure
hold on
for i=1:length(K_p_no);
ChEq{i} = [K_p_no(i)*50 K_p_no(i)*100 1 K_p_no(i)*60]; %characteris eqn (K_p*50*s^2 + K_p*100*s + s^2 + K_p*60) of the T_s, set =0 to find the poles in the s-plane
pol{i} = roots(ChEq{i}); %poles on s-plane
plot(real(pol{i}), imag(pol{i}), 'rx')
xlabel('Real Axis (seconds^-1)');
ylabel('Imaginary Axis (seconds^-1)')
end
hold off
grid
.
  2 Comments
Franz Adam Magallanes
Franz Adam Magallanes on 26 Jan 2021
It is what I'm looking for code-wise. The values are resulted are really really close to each other which makes the graph look like it only plotted one. The equation provided by my professor was incorrect.
Thanks for the coding help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!