Using Newton method develop a similar python program to compute the cubical root of n for any real number n.
时间: 2024-05-24 12:13:50 浏览: 108
Sure, here's a Python program using Newton's method to compute the cubical root of any real number n:
def cubical_root(n):
x = n/3.0 # initial guess
while True:
fx = x*x*x - n
if abs(fx) < 1e-6:
return x
fpx = 3*x*x
x = x - fx/fpx
You can call the function with any real number n, and it will return its cubical root. For example, cubical_root(27) will return 3.
阅读全文