error message when poles are in RHP
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have error message in this code when i have poles in RHP.
Attempted to access r2(2); index out of bounds because numel(r2)=1.
Error in B4 (line 46)
wt = [0 r2(2) r2(1)] ;
% PID stabilizing set
clear all;
syms s;
kp = sym('kp','real');
ki = sym('ki','real');
kd= sym('kd','real');
w = sym('w','real');
N = [595e07]; % Numerator
D = [1 -972.2 4.34e6]; % Denominator
tam_N = size(N);
tam_D = size(D);
n = tam_D (2) -1;
m = tam_N (2) -1;
ze = roots(N); % Zeros of N(s)
l = 1;
nz = 0;
for k = 1:m
if real(ze(k)) > 0
nz = l; % RHP Zeros of N(s)
l = l + 1;
end
end
signature = n - m + 1 + 2*nz; % Signature number
D_s = poly2sym(D,s); % D(s)
N_s = poly2sym(N,s); % N(s)
N_ms = subs(N_s , -s); % N(-s)
Delta = s*D_s + (ki+kd*s^2)*N_s + kp*s*N_s; % ...Characteristic equation
Delta = collect(Delta ,s); % simplify expression in ...terms of s
V_s = collect(Delta*N_ms ,s); % V = Delta*N(-s)
V = subs(V_s , 1i*w); % V(jw)
Vr = real(V); % Real part of V
Vi = imag(V); % Imaginary part of V
for kp_f = -8.5:0.2:4.22 % Evaluate for a fixed Kp
f_kp = subs(Vi , kp , kp_f); % substitute value of Kp
f_Vi = sym2poly(f_kp); % convert to polynomial
r = roots(f_Vi); % find the roots
tam3 = size(r);
l = 1;
r2 = 0;
for k = 1: tam3
if imag(r(k)) == 0 && real(r(k)) > 0 % select ...real , positive roots
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]; % [kd ki kp]
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;
0 Kommentare
Antworten (1)
KALYAN ACHARJYA
am 16 Nov. 2019
Bearbeitet: KALYAN ACHARJYA
am 16 Nov. 2019
The problem is here
for k = 1: tam3
if imag(r(k)) == 0 && real(r(k)) > 0 % select ...real , positive roots
r2(l) = real(r(k));
l = l + 1;
end
In the code if condition doesnot hold true, hence, it unable to evaluate r2 array elemnets (It bypassing if condition). Therefore without r2(2) and r2(1), how can you assigned vaue to "wt"
wt=[0 r2(2) r2(1)] ;
Till above for loop, r2=0 as predefined before the for loop, it consider r(1)=0 but what about r(2).
The solution is: Both Condition Must be Satisfied on imag(r(k)) == 0 and real(r(k))>0,
or
change the conditions.
Hoe you get the issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Stability Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!