Error initiating chaotic tent population
7 ビュー (過去 30 日間)
古いコメントを表示
Im trying to initialize a chaotic tent population I got an error while running this code:
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in tent_map_fix (line 17)
if T(k-1,j) <= 0.5
n = 300; % population
D = 2; % dimension
M = 1000; % max iter tent map
lb = [0 0]; % lower bound
ub = [1 1]; % upper bound
v = 2*rand; % random tent map paramater
for i=1:n
for j=1:D
T(1,j)=rand;
K = 0;
for k=2:M
K = K+1;
if T(k-1,j) <= 0.5
X(K,j) = lb(j) + (v*T(k-1,j) + rand/(n))*(ub(j) - lb(j));
else
X(K,j) = lb(j) + (v*(1 - T(k-1,j)) + rand/(n))*(ub(j) - lb(j));
end
end
end
end
0 件のコメント
回答 (1 件)
Manikanta Aditya
2023 年 4 月 18 日
Hi Rivaldi,
As per my understanding, you are facing an issue with array access. The error message suggests that the index ‘1’ is being exceeded, which means that the size of the array being accessed is less than or equal to 1. Here loop is not initialized correctly.
In your code ‘T’ is not initialized, you can initialize it by adding:
T = zeros(M,D);
In your code ‘T’ is not initialized, you can initialize it by adding:
n = 300; % population
D = 2; % dimension
M = 1000; % max iter tent map
lb = [0 0]; % lower bound
ub = [1 1]; % upper bound
v = 2*rand; % random tent map paramater
for i=1:n
T = zeros(M,D); % initialize T
for j=1:D
T(1,j)=rand;
K = 0;
for k=2:M
K = K+1;
if T(k-1,j) <= 0.5
X(K,j) = lb(j) + (v*T(k-1,j) + rand/(n))*(ub(j) - lb(j));
else
X(K,j) = lb(j) + (v*(1 - T(k-1,j)) + rand/(n))*(ub(j) - lb(j));
end
end
end
end
I hope this resolves the issue you were facing.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!