我需要编写一个程序来使用 Newton-Raphson Method 使用猜测估计来找到平方根。Newton-Raphson 方法的方程为:
xn+1 = xn-xn**2 − a/2*xn
其中 n 是迭代次数。
分配告诉我应该在 1 和指定的迭代总数之间执行一个循环。并且循环的每一步,“解”的当前值都应该用于计算解的下一个值,以方程指定的形式。
提示:请记住,为变量赋值会在执行赋值之前计算等号的右侧。这意味着计算每个新值只需要一个 x 变量;你不需要 'old_x' 和 'new_x' 或类似的。
这是我到目前为止所拥有的:
program assign_10_2
implicit none
real :: a, b, x
integer :: c, i, j
write(*,*) 'please enter a value to determine the square root of'
read(*,*) a
write(*,*) 'please enter a value to use as the initial guess for the solution'
read(*,*) b
write(*,*) 'please enter a value for how many iterations it should perform to calculate the value'
read(*,*) c
write(*,*) a, b , c
do i= 1, c, 1
x = b-((b**2-a)/2*b)
write(*,*) i, x
end do
end program assign_10_2
我绝不是在寻求答案,只是朝着正确的方向前进。我对编程完全陌生,这一切都让我感到困惑。我知道我在方程式方面做错了。