I am trying to iterate and plot the Logistic map nonlinear function given by the equation: x[n+1] = 4*x[n]*(1-x[n])
. I have found an implementation of the function here https://www.mathworks.com/matlabcentral/answers/122101-plotting-f-x-as-a-function-of-x-logistic-map
I have followed the same thing only the number of points N
and the starting initial condition is different in my implementation. I don't know why I am getting no values in the output; mostly are zero value. When the initial condition is x[1] = 0.5
, I get the weird plot as given in the picture. But when the initial condition is say 0.3, then I get the proper Logistic map. Theoretically, the initial condition can be any number between 0 and 1. So, why does the code not work when the initial condition is 0.5?
What is the problem?
N=20000; % number of data points
x = zeros(1,N);
x(1) = 0.5; % initial condition (can be anything from 0 to 1)
for n = 1:N
x(n+1) = 4*x(n)*(1-x(n));
end
plot(x(1:N),x(2:N+1),'rs-')
xlabel('x_n')
ylabel('x_{n+1}')
Here is the plot
The result you're getting is correct. Let me explain it with the cobweb diagram below (source: http://sites.saintmarys.edu/%7Esbroad/example-logistic-cobweb.html)
The parabola is the curve y = 4*x*(1-x)
, the blue linear curve is y=x
. The way the points x[n]
are determined is the following:
(x0,y(x0))
(often the line with (x0,0)
is drawn)x[n+1]
.x[n]=x[n-1]
(stable point) or x[n]=x[n-m]
(periodicity)Note the stable points are where the parabola and linear curve intersect.
Applying this method to with your parameters gives:
(0.5,1)
(1,1)
(1,0)
(this is x[1]
)(0,0)
(0,0)
(this is x[2]
)(0,0)
(0,0)
(this is x[3]
)So you just happen to end up the stable point.