如何用FORTRAN编写实现:用牛顿迭代法求a**(1⼀3)的近似值,取精度10的负5次方?

2025-03-10 08:51:14
推荐回答(1个)
回答1:

下面的程序只需要把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