clear all;
func='x^2-2'; kmax=50; toll=10^-10;
x=1; fxold=eval(func); xold=x;
x=2; fx=eval(func);
format long
err=toll+1;
k=0;
while k<kmax & err>toll
   k=k+1
   xnew=x-(xold-x)*fx/(fxold-fx)
   xold=x;
   fxold=eval(func);
   x=xnew;
   fx=eval(func);
   err=abs(x-xold);
end;

format short


