Error initiating chaotic tent population
1 次查看(过去 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 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!