err=feval(f,x0);
n=0;
while(abs(err)>tol)
x1=x0-feval(f,x0)/feval(df,x0);
err=abs(x1-x0);
x0=x1;
n=n+1;
if(err
break,
end
end
solu=x0;
fsolu=feval(f,x0);
if(solu<0)
disp('Negative root obtained');
else
fprintf('the minimum number of iterations is %4dn',n)
fprintf('the value of positive root is %8.6fn',solu)
end
好久前的一个程序