Attempted to access r2(2); index out of bounds because numel(r2)=1.
Error in B4 (line 46)
wt = [0 r2(2) r2(1)] ;
clear all;
syms s;
kp = sym('kp','real');
ki = sym('ki','real');
kd= sym('kd','real');
w = sym('w','real');
N = [595e07];
D = [1 -972.2 4.34e6];
tam_N = size(N);
tam_D = size(D);
n = tam_D (2) -1;
m = tam_N (2) -1;
ze = roots(N);
l = 1;
nz = 0;
for k = 1:m
if real(ze(k)) > 0
nz = l;
l = l + 1;
end
end
signature = n - m + 1 + 2*nz;
D_s = poly2sym(D,s);
N_s = poly2sym(N,s);
N_ms = subs(N_s , -s);
Delta = s*D_s + (ki+kd*s^2)*N_s + kp*s*N_s;
Delta = collect(Delta ,s);
V_s = collect(Delta*N_ms ,s);
V = subs(V_s , 1i*w);
Vr = real(V);
Vi = imag(V);
for kp_f = -8.5:0.2:4.22
f_kp = subs(Vi , kp , kp_f);
f_Vi = sym2poly(f_kp);
r = roots(f_Vi);
tam3 = size(r);
l = 1;
r2 = 0;
for k = 1: tam3
if imag(r(k)) == 0 && real(r(k)) > 0
r2(l) = real(r(k));
l = l + 1;
end
end
wt = [0 r2(2) r2(1)] ;
tam_w = size(wt);
R(1) = subs(Vr , w, wt(1));
C1(1,:) = [0,coeffs(R(1)), 0];
Te(1,:) = [0,ki ,0];
R(tam_w (2)) = subs(Vr , w, wt(tam_w (2)));
for k=2: tam_w (2)
R(k) = subs(Vr , w, wt(k));
[C1(k,:),Te(k,:)] = coeffs(R(k));
end
C1 = double(C1);
A = -[C1(1 ,1) C1(1 ,2) 0;-C1(2 ,1) -C1(2 ,2) 0;C1(3 ,1) C1(3 ,2) 0];
b = -[-C1(1 ,3);C1(2 ,3);-C1(3 ,3)];
lb = [-300,-300, kp_f ];
ub = [300 ,300 , kp_f ];
plotregion(A,b,lb ,ub ,'y');
hold on;
axis equal
xlabel('kd');
ylabel('ki');
zlabel('kp');
end
axis square;