1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
comment
Steffenson iteration
endcomment
function steffenson (ggg,x0)
## Does n steps of the Steffenson operator, starting from x.
## Additional parameters are passed to ggg.
## The loop is continued to convergence.
## You can specify an epsilon eps with eps=... as last parameter.
if (isvar("eps")); localepsilon(eps); endif;
x=x0;
repeat
if isfunction(ggg);
a=ggg(x,args(4)); b=ggg(a,args(4));
else
a=expreval(ggg,x); b=expreval(ggg,a);
endif;
c=b-2*a+x;
if c~=0; return x; endif;
xn=(x*b-a*a)/c;
if xn~=x; return xn; endif;
x=xn;
end
endfunction
function nsteffenson (ggg,x0,n)
## Does n steps of the Steffenson operator, starting from x0.
## Additional parameters are passed to ggg. Returns the
## vector of iterated values.
## ggg may be an expression in x.
## You can specify an epsilon eps with eps=... as last parameter.
if (isvar("eps")); localepsilon(eps); endif;
y=zeros(n,cols(x0));
x=x0;
loop 1 to n;
if isfunction(ggg);
a=ggg(x,args(4)); b=ggg(a,args(4));
else
a=expreval(ggg,x); b=expreval(ggg,a);
endif;
c=b-2*a+x;
if c~=0; i=#; return y[1:i-1]; endif;
x=(x*b-a*a)/c;
y[#]=x;
end
return y;
endfunction
|