annotate sequences/@seq/limit.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@3
|
1 % limit - Get the limit of an infinite sequence if it exists
|
samer@3
|
2 %
|
samer@3
|
3 % limit ::
|
samer@3
|
4 % (A,A->nonneg) ~ 'metric',
|
samer@3
|
5 % seq(A), ~ 'sequence of converging values',
|
samer@3
|
6 % options {
|
samer@3
|
7 % maxit :: natural/10e6 ~ 'maximum iterations';
|
samer@3
|
8 % tol :: nonneg/1e-5 ~ 'convergence tolerance'
|
samer@3
|
9 % }
|
samer@3
|
10 % -> A, natural.
|
samer@3
|
11
|
samer@3
|
12 function [y,its]=limit(d,X,varargin)
|
samer@37
|
13 opts=options('maxit',10e6,'tol',1e-5,varargin{:});
|
samer@3
|
14
|
samer@3
|
15 tol=opts.tol;
|
samer@3
|
16 S.x=head(X);
|
samer@3
|
17 S.X=next(X);
|
samer@3
|
18 S.f=false;
|
samer@3
|
19 S.its=0;
|
samer@3
|
20 S=iterate(@converger,S,'its',opts.maxit);
|
samer@3
|
21 y=S.x;
|
samer@3
|
22 its=S.its;
|
samer@3
|
23
|
samer@3
|
24 function S=converger(S)
|
samer@3
|
25 [xx,S.X]=decons(S.X);
|
samer@3
|
26 S.its=S.its+1;
|
samer@3
|
27 if d(S.x,xx)<tol, S=[]; else S.x=xx; end
|
samer@3
|
28 end
|
samer@3
|
29 end
|