index exceeds matrix dimensions

P=0.4;
T=0.5;
a=2;
for i=1:max_it
if x(i)>=0 && x(i)<P %(Error Here)
x(i+1)=x(i)/P;
end
if x(i)>=P && x(i)<=T
x(i+1)=(x(i)-T)/(P-T);
end
if x(i)>=T && x(i)<=1
x(i+1)=a*((x(i)-T)/1-T)*(1-(x(i)-T)/(1-T));
end
% if x(i)>=1-P && x(i)<1
% x(i+1)=(1-x(i))/P;
% end
G(i) =x(i);
end

Risposte (2)

Walter Roberson
Walter Roberson il 24 Dic 2019

0 voti

We do not know what you initialized x as.
You probably did not pre-allocate x; you are probably counting on it growing as you go. However notice that you only ever grow x conditionally: you stop growing x if you encounter an element that is negative or greater than 1.
deepak kumar
deepak kumar il 24 Dic 2019
Modificato: Walter Roberson il 24 Dic 2019
P=0.4;
T=0.5;
a=2;
max_it=100;
x(1)=0.7;
Value=1;
O=zeros(1,max_it);
for i=1:max_it
if x(i)>=0 && x(i)<P %(Error Here)
x(i+1)=x(i)/P;
end
if x(i)>=P && x(i)<=T
x(i+1)=(x(i)-T)/(P-T);
end
if x(i)>=T && x(i)<=1
x(i+1)=a*((x(i)-T)/1-T)*(1-(x(i)-T)/(1-T));
end
% if x(i)>=1-P && x(i)<1
% x(i+1)=(1-x(i))/P;
% end
G(i) =x(i)*Value;
end
case 7
%Sine map
for i=1:max_it
x(i+1) = sin(pi*x(i));
G(i)=(x(i))*Value;
end

1 Commento

The second x you generate is negative, and as I pointed out before, you stop growing x as soon as you find a negative value.

Questa domanda è chiusa.

Richiesto:

il 24 Dic 2019

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by