寻找大量的立方根

时间:2010-12-05 19:16:11

标签: root

我需要找到向上舍入的巨大(5k位左右)数字的立方根。 我该怎么做?

2 个答案:

答案 0 :(得分:5)

如果GNU bc适合你,可能会这样做:

http://phodd.net/gnu-bc/bcfaq.html#bccbrt

编辑:

它基本归结为:

$ bc -l
define cbrt(x) { return e(l(x)/3) }

您需要增加scale变量才能获得必要的精度:

$ bc -l
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

define cbrt(x) { return e(l(x)/3) }

cbrt(10000000000000000000000000000000000000000000000000000000000000000000)^3
9999999999999999999845725361475980907263179272258247094885777761435.\
89049462743995306310

scale=1000

cbrt(10000000000000000000000000000000000000000000000000000000000000000000)^3
9999999999999999999999999999999999999999999999999999999999999999999.\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999999999999999999999999\
99999999999999999999999999999999999999999999999978254573198390239858\
069738839057154871628814670160708326688382280410

正如您可能已经注意到的那样,在不增加比例变量的情况下(在我的系统上它默认为20),结果远不及您所需的精度。

答案 1 :(得分:0)

这是straightforward iterative algorithm。请注意,他们提到了special case of square roots

  

特殊情况是熟悉的   平方根算法。通过设置n =   2,步骤2中的迭代规则   成为平方根迭代规则

可以将相同的技术应用于立方体根:设置n = 3并迭代直到达到所需的precision

对于注释中的规范“它需要四舍五入到最接近的整数并且是精确的”,这只适用于具有整数或有理数立方根的数字。也就是说,您可以使用引用的算法通过迭代找到这个精度水平的答案,直到一次迭代的结果与下一次迭代的结果之间的差异小于0.5。这足够接近,以确保未来的迭代不会远离那个近似。

这是一个数值分析课的练习吗?如果是这样,我怀疑这正是为什么问题是这样提出的:教师希望你将一般规则应用于具体问题。