function y=fixpoint(f,x0,varargin)
% fixpoint - Find the fixed point of a function by repeated evaluation
%
% fixpoint :: 
%    (A->A)	~'function to iterate',
%    A      ~'initial value',
%    options {
%       its    :: natural/inf ~'maximimum numbert of iterations';
%       testfn :: (A,A->boolean) ~'convergence test'
%    }
% -> maybe A ~'final value or nan if none'.


opts=prefs('its',inf,'testfn',@epseq,varargin{:});

conv=opts.testfn;
its =opts.its; 
i=0; while i<its
	x=f(x0);
	if conv(x0,x), break; end
	x0=x; i=i+1;
end

if i<its, y=x; else y=nan; end

function b=epseq(x,y), b=abs(y-x)<=eps(x);
