Info

This question is closed. Reopen it to edit or answer.

I'm trying to figure out how to plot how the gain of a system (k) changes within the interval of -5 to 20 incrementing by 0.5. The code I have so far is below. I'm pretty sure I must be close. The 1 and 10 are given for the q values.

1 view (last 30 days)
figure (4)
hold on
q=[1 10 i];
for i=-5:0.5:20
end
p2=roots(q);
plot(real(p2), imag(p2), 'rx')
line([0,0], [-6,6])
line([-12,1], [0,0])
xlabel('Real Axis'), ylabel('Imaginary Axis')
title('k= -5<k<20');

Answers (1)

Image Analyst
Image Analyst on 3 Sep 2014
Well you need to have something inside the for loop of course. Yours is empty! Do you think may lines like the q and p2 lines, and others, might go inside the loop???
  2 Comments
Joshua Brantley
Joshua Brantley on 3 Sep 2014
Ok, I'm still confused on how to actually implement this. I changed the for loop to the following
for m=-5:0.5:20
q=[1 10 m];
p2(m)=roots(q(m));
plot(real(p2(m)), imag(p2(m)), 'rx')
end
Is this going towards the right track? When I run this one it says I can't use -5 as an index. Thank you for your help!
Image Analyst
Image Analyst on 3 Sep 2014
You can't have negative indexes of an array. Just have p2 and it will put all the roots into an array called p2. Then you don't want the (m) in the plot statement either. Then you need to have "hold on" after the plot or else new plots will blow away old ones so fast you won't even see them. If you have "hold on" then it will keep all the plots on the graph.

Community Treasure Hunt

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

Start Hunting!