Actions

Sayres logstic M-code: Difference between revisions

From Santa Fe Institute Events Wiki

(pasting in code I wrote to play with lecture concepts)
 
m (really hard to properly format MATLAB code!)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<code>
function X = logistic(R, N, X0);
function X = logistic(R, N, X0);
% Compute the logistic equation given a control parameter R,  
% Compute the logistic equation given a control parameter R,  
% a number of iterations N and an initial state X0.
% a number of iterations N and an initial state X0.
%
%
%  X = logistic(R, [N=10], [X0=0.5]);
%  X = logistic(R, [N=10], [X0=0.5]);
%
%
%
%
% ras, 06/02/08.
% ras, 06/02/08.
if nargin < 1, error('Need conrol param R'); end
if nargin < 1, error('Need conrol param R'); end
if notDefined('N'), N = 10; end
if notDefined('N'), N = 10; end
if notDefined('X0'), X0 = 0.5; end
if notDefined('X0'), X0 = 0.5; end


X(1) = X0;
X(1) = X0;


for n = 2:N
for n = 2:N
X(n) = R * X(n-1) * (1 - X(n-1));
X(n) = R * X(n-1) * (1 - X(n-1));
end
end


return
return
</code>

Latest revision as of 20:04, 2 June 2008

function X = logistic(R, N, X0);

% Compute the logistic equation given a control parameter R, 
% a number of iterations N and an initial state X0.
%
%  X = logistic(R, [N=10], [X0=0.5]);
%
%
% ras, 06/02/08.
if nargin < 1, error('Need conrol param R');	end
if notDefined('N'),		N = 10;					end
if notDefined('X0'),	X0 = 0.5;				end
X(1) = X0;
for n = 2:N
	X(n) = R * X(n-1) * (1 - X(n-1));
end
return