Error initiating chaotic tent population

1 visualización (últimos 30 días)
Rivaldi
Rivaldi el 14 de Abr. de 2023
Respondida: Manikanta Aditya el 18 de Abr. de 2023
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.

Respuestas (1)

Manikanta Aditya
Manikanta Aditya el 18 de Abr. de 2023
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.

Categorías

Más información sobre Mathematics and Optimization en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by