0
votes

I need to plot the Root Locus with a changing "k" of a given transfer function without using any special Matlab functions i.e., "rlocus", "tf". I'm allow to use roots. The code bellow displays an error/warning message (Subscript indices must either be real positive integers or logicals.) that I have not been able to figure out .

See my code.

%In vector form
num = input('Enter the coefficients of numerator of J(s): ');
%In vector form 
den = input('Enter the coefficients of denominator of J(s): ');
qs = 0; 
for k = 0:0.1:1000; 
qs(k,:) = roots(den + num.*k); 
end; 
plot(qs,'+'), xlabel('\sigma'), ylabel('j\omega'), title ('Root-Locus'), grid

Thank you

1
You are indexing qs(k,:) but q is not always an integer, you're trying to do q(0,:)=..., q(0.1,:)=..., etc. The Matlab error message told you exactly what the problem was.David
Thank you for answering my question, I need k to go from zero to a large number and if I try to change it to start at 1, I get another error message (Subscripted assignment dimension mismatch.)konkras

1 Answers

0
votes

As @David already described in a comment, the problem is that you are using k=0:0.1:1000 as index. You are therefore trying to access qs(0), qs(0.1), ..., which is not possible in MATLAB. The index has to be an integer value larger than 0, i.e. starting at 1. (unlike in most programming languages, where indexing starts at 0).

I would suggest separating k and the index variable by creating a vector k containing 0:0.1:1000 and then using a separate variable (e.g. ii) as index variable in the for loop:

%In vector form
num = input('Enter the coefficients of numerator of J(s): ');
%In vector form 
den = input('Enter the coefficients of denominator of J(s): ');
qs = 0; 
k = 0:0.1:1000;
for ii = 1:length(k)
    qs(ii,:) = roots(den + num.*k(ii)); 
end; 
plot(qs,'+'), xlabel('\sigma'), ylabel('j\omega'), title ('Root-Locus'), grid