Index exceeds array bounds. Error in PID_optimized (line 14) gc = tf(K(i)*([1 2*a(j) a(j)^2]),[1 0]); %controller transfer fx Gc

4 ビュー (過去 30 日間)
Hi all
Trying to run this code. I am getting an error message 'index exceeds array bounds. Error in PID_optimized (line 14). The code is given below
clc
%G(s) = 1.2/0.36s^2+1.86s^2+2.5s+1
% Gc(s) = K(s+a)^2/s
% Required to test for K and a values
K = [2.0 2.2 2.4 2.6 2.8 3.0];
a = [0.5 0.7 0.9 1.1 1.3 1.5];
%evaluate closed-loop unit-response at each 'K' and 'a' combination that
%will yield the maximum overshoot less than 10%
t = 0:0.01:5;
g = tf([1.2],[0.36 1.86 2.5 1]);
K =0; %initialization
for i = 1:6
for j = 1:6
gc = tf(K(i)*([1 2*a(j) a(j)^2]),[1 0]); %controller transfer fx Gc
G =gc*g/(1+(gc*g)); %closde-loop transfer function
y = step(G,t);
m = max(y);
if m<1.10
K = K+1;
Solution(K,:) = [K(i) a(j) m];
end
end
end
solution; %print solution table

採用された回答

James Browne
James Browne 2019 年 6 月 12 日
Greetings,
I believe your problem is on line 10 of your code. On line 10, you redefine K as a single value rather than a vector, as such, the only legal index value for K, after line 10, is 1. It appears that you are using K as a vector and as an indexing variable.
I made the changes for you (and fixed the spelling error on line 24 and removed the semicolon so that the variable would display in the command terminal), here you go!
clc
%G(s) = 1.2/0.36s^2+1.86s^2+2.5s+1
% Gc(s) = K(s+a)^2/s
% Required to test for K and a values
K = [2.0 2.2 2.4 2.6 2.8 3.0];
a = [0.5 0.7 0.9 1.1 1.3 1.5];
%evaluate closed-loop unit-response at each 'K' and 'a' combination that
%will yield the maximum overshoot less than 10%
t = 0:0.01:5;
g = tf([1.2],[0.36 1.86 2.5 1]);
Idx =0; %initialization
for i = 1:6
for j = 1:6
gc = tf(K(i)*([1 2*a(j) a(j)^2]),[1 0]); %controller transfer fx Gc
G =gc*g/(1+(gc*g)); %closde-loop transfer function
y = step(G,t);
m = max(y);
if m<1.10
Idx = Idx+1;
Solution(Idx,:) = [K(i) a(j) m];
end
end
end
Solution %print solution table
  2 件のコメント
polycarp onyebuchi
polycarp onyebuchi 2019 年 6 月 14 日
it worked. thanks alot
James Browne
James Browne 2019 年 6 月 15 日
You are very welcome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by