function y=fcnIteration(fcn,x,maxIt,tol)
% Iterate the function fcn (for g(x))
% starting with the value x: x := g(x)
% until x changes by less than tol
% Usage: a=fcnIteration('cos',0.23,40,1e-6)
% K. Ming Leung, 02/13/03

dx=10; loop=1;
while (abs(dx) > tol & loop < maxIt)
    xnew=feval(fcn,x); % xnew = g(x)
    dx=xnew-x; % change in x
    x=xnew; loop=loop+1;
end
y=x; loop,