fixed-point for solve non linear equation



There is a block for solve non linear equation
with fixed-point method: f(x)=x

puntiter(f,xv,tol,nmax):=block([x0,x1,diff,count],
count:1,
x0:xv,
print(x0),
x1:float(ev(f,x:x0)),
print(x1),
diff:x1-x0,
x0:x1,
while tol<abs(diff) and count <nmax  do(
count:count+1, x1:float(ev(f,x:x0)),print(x1),
diff:x1-x0,
x0:x1),print("iter =", count)
)$

Example:
f:1/(2*x^2+1);
puntiter(f,5.0,0.000001,90);

f:cos(x);
puntiter(f,1.0,0.000001,90);

Luigi Marino