annotate 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 |
|
rev |
line source |
samer@4
|
1 function y=fixpoint(f,x0,varargin)
|
samer@4
|
2 % fixpoint - Find the fixed point of a function by repeated evaluation
|
samer@4
|
3 %
|
samer@4
|
4 % fixpoint ::
|
samer@4
|
5 % (A->A) ~'function to iterate',
|
samer@4
|
6 % A ~'initial value',
|
samer@4
|
7 % options {
|
samer@4
|
8 % its :: natural/inf ~'maximimum numbert of iterations';
|
samer@4
|
9 % testfn :: (A,A->boolean) ~'convergence test'
|
samer@4
|
10 % }
|
samer@4
|
11 % -> maybe A ~'final value or nan if none'.
|
samer@4
|
12
|
samer@4
|
13
|
samer@37
|
14 opts=options('its',inf,'testfn',@epseq,varargin{:});
|
samer@4
|
15
|
samer@4
|
16 conv=opts.testfn;
|
samer@4
|
17 its =opts.its;
|
samer@4
|
18 i=0; while i<its
|
samer@4
|
19 x=f(x0);
|
samer@4
|
20 if conv(x0,x), break; end
|
samer@4
|
21 x0=x; i=i+1;
|
samer@4
|
22 end
|
samer@4
|
23
|
samer@4
|
24 if i<its, y=x; else y=nan; end
|
samer@4
|
25
|
samer@4
|
26 function b=epseq(x,y), b=abs(y-x)<=eps(x);
|