下面的程序只需要把f(x),和导数g(x)改一下就行了
program ex20
implicit none
external f,g !g(x)是f(x)的导函数
real xr,x1,f,g
print*,'input x1:'
read*,x1
do
xr=x1-f(x1)/g(x1)
if(abs(f(xr))<1.0e-6) exit
x1=xr
end do
print*,'result:',xr
end program ex20
function f(x)
implicit none
real f,x
f=x**3-2*x**2+x-1
end function
function g(x)
implicit none
real g,x
g=3*x**2-4*x+1
end function