function [x,ko]=newton(x0,tol,kmax,f,df)
x_old=x0; ko=0; x=[x0];
step=realmax; k=0; 
while (abs(step) > tol) & (k < kmax)
    k=k+1; fx=feval(f,x_old);
    if fx == 0 return; end
    dfx=feval(df,x_old); 
    if dfx == 0 ko=1; return; end
    step=-fx/dfx; x_new=x_old+step;
    x=[x; x_new]; x_old=x_new;
end
ko=1;
