function x=logistic(R,xinit,N)
% LOGISTIC caclulates a solution of the logistic map.
% with parameter R, an initial condition xinit and
% the number of iterations N.
% Usage: x=logistic(R,xinit,N)

% Copyright(C) 2002 Tohru Ikeguchi, All Rights Reserved

% Default value setting
if nargin<1,R=3.999999;end
if nargin<2,xinit=0.2; end
if nargin<3,N=1000;    end

% Allocate an Nx1 vector as an output x.
x=zeros(N,1);

% Calculate x_n for n=1,2,...,N.
x(1)=xinit;
for n=1:N-1
    x(n+1)=R*x(n)*(1-x(n));
end
