题解 | #求解立方根#
求解立方根
http://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
牛顿迭代法求解立方根
求解以下公式
f(x) = x^3-a=0
泰勒展开
f(x) = f(x0)+f'(x0)(x-x0)=0
求解得
x = (2*x0^3+a)/(3x0^2)
每次更新x
a为所要求解的值
x0 为上次的x值
n = float(input())
x = n/2
while abs(x**3-n)>0.00001:
x = (2*x**3+n)/(3*x**2)
print(round(x,1))