Error initiating chaotic tent population

조회 수: 1 (최근 30일)
Rivaldi
Rivaldi 2023년 4월 14일
답변: Manikanta Aditya 2023년 4월 18일
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