•計算一個數字的立方根,不使用庫函數
詳細描述:
•接口說明
原型:
public static double getCubeRoot(double input)
輸入:double 待求解參數
返回值:double 輸入參數的立方根,保留一位小數
牛頓迭代法:之前看到很多人說這種方法,光看代碼還是不能理解什么意思,后來看了這篇博客理解了https://blog.csdn.net/sunbobosun56801/article/details/78088085
number=float(raw_input().strip()) #初始化一個估計解
t=5 while abs(t*t*t-number)>0.01: t=t-(t*t*t*0.1-number*0.1)/(3.0*t*t) print "%.1f" % t