function x=NewRaph(x0,f,fprime,tol)x(1)=x0;i=1;gx=x(i)-f(x(i))/fprime(x(i));while(abs(x(i)-gx)>tol) gx=x(i); x(i+1)=x(i)-f(x(i))/fprime(x(i)); i=i+1;end调用:y=NewRaph(1,@(x)x-cos(x),@(x)1+sin(x),10^-6) y(end)即为逼近值