Error initiating chaotic tent population

2 次查看(过去 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
Index in position 1 exceeds array bounds. Index must not exceed 1.

回答(1 个)

Manikanta Aditya
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics and Optimization 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by