function a = fditer(fun, x, p, n )

%   Y = FDITER(FUN,X,P,N) iterates a finite-difference 
%   equation a given number of times.
%
%   FUN is the function, which must be of the form f(X,P)
%   where P is the function parameter.
%   X is the initial condition.
%   FDITER returns a column vector Y of length N.
% 
%   Example: FDITER('quadmap', 0.32323, 4, 100)
%   calculates 100 iterations of the quadratic map
%   starting from 0.32323 with parameter value 4
%
%   Note: all functions to be iterated must have the same syntax as
%   quadmap , i.e quadmap(x,p).

%   Copyright 2003
%   Centre for Nonlinear Dynamics in Physiology and Medicine

a = zeros(n,length(x));
nx = x;

for k = 1:n
  nx = feval( fun, nx, p);
  a(k,:) = nx;
end