Domanda

Given a function (call it sys(s)), we can use matlab: rlocus(sys) to plot the root locus of that function.

However,if we are given a function with a parameter (say b), eg sys(s)=(2s+2+b)/s , how can I use matlab to plot the rlocus(sys) as a function of the parameter b?

È stato utile?

Soluzione

Let's say b changes between 1 and 100 with intervals of 1.

b = 1:100;

We need to create axes and hold them, so that we can plot root loci on top of each other.

axes();
hold('on');

Now we need to create a transfer function for each b and plot its root locus.

for idx = 1:length(b)
   sys = tf([2 2+b(idx)], [1 0]);
   rlocus(sys);
end

This is the resulting plot: Root locus

I could not find a vectorized solution, so it takes quite a long time. This took 45 seconds on my computer. If you need to calculate many values, you will need a vectorized solution.


To add a legend, you need to create a cell array to store b values.

legendStr = cell(1, length(b));

Then, inside the for loop you need to convert b values to string and store them in legendStr.

legendStr{idx} = num2str(b(idx));

After the for loop add the legend to the plot.

legend(legendStr)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top