Mercurial > hg > ishara
view general/numerical/fixpoint.m @ 61:eff6bddf82e3 tip
Finally implemented perceptual brightness thing.
author | samer |
---|---|
date | Sun, 11 Oct 2015 10:20:42 +0100 |
parents | beb8a3f4a345 |
children |
line wrap: on
line source
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=options('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);