数学中一个很奇怪的问题
我在 mma v7.0 中这样做:
r[x_] := Rationalize[x, 0]; N[Nest[Sqrt, 10., 53] // r, 500]
它给了我 1.000000000000000222044604925031308084726333618164062500000000000000000
但是,如果我更进一步 N[Nest[Sqrt, 10., 54] // r, 500]
我得到的全是零。有谁知道解释,或者这是一个错误?
此外,看起来这种从解决方案 Nest[Sqrt, 10., 53]
中产生更多数字的方法效果不佳。如何获得此计算的更多有效数字?
非常感谢。
编辑
如果我执行Nest[Sqrt, 10., 50]
,我仍然得到很多有效数字。
I am doing this in mma v7.0:
r[x_] := Rationalize[x, 0];
N[Nest[Sqrt, 10., 53] // r, 500]
It gave me1.000000000000000222044604925031308084726333618164062500000000000000000
However, if I go one step furtherN[Nest[Sqrt, 10., 54] // r, 500]
I got all zeros. Does anybody know an explanation, or it is a bug?
Besides, looks like this way to produce more digits from the solution Nest[Sqrt, 10., 53]
is not working very well. How to obtain more significant digits for this calculation?
Many thanks.
Edit
If I did Nest[Sqrt, 10., 50]
, I still got a lot of significant digits.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果执行此操作 54 次,则除了零之外,没有任何有效数字。因此,您所做的合理化(仅保留位模式)给出了您所看到的。
Out[180]//输入表单=
1.0000000000000002
Out[181]//输入表单=
1.
4503599627370497/4503599627370496
Out[183]= 1
好奇的是:问题不在于迭代计算退化意义上的精度损失。事实上,迭代这些平方根实际上提高了精度。我们可以通过 bignum 输入看到这一点。
Out[188]//输入表单=
1.0000000000000001278191493200323453724568038240908339267044`36.25561976585499
这是实际的问题。当我们使用机器数字时,经过 54 次迭代后,得到的机器双精度数中除了零之外没有其他有效数字。也就是说我们对数量的大小限制就是原因。
原因并不算太神秘。将结果值称为 1+eps。然后我们有 (1+eps)^(2^54) 等于(接近近似)10。然后二阶展开表明 eps 必须小于机器 epsilon。
首先[选择[
每股收益/。 N[求解[Sum[eps^j*二项式[2^54, j], {j, 2}] == 9, eps]],
Head[#] === Real && #> 0 &]]]
Out[237]//输入表单=
1.864563472253985*^-16
输出[235]= 2.22045*10^-16
丹尼尔·利希布劳
沃尔夫勒姆研究公司
You have no significant digits other than zeros if you do this 54 times. Hence rationalizing as you do (which simply preserves bit pattern) gives what you saw.
Out[180]//InputForm=
1.0000000000000002
Out[181]//InputForm=
1.
4503599627370497/4503599627370496
Out[183]= 1
For the curious: the issue is not loss of precision in the sense of degradation with iterations computation. Indeed, iterating these square roots actually increases precision. We can see this with bignum input.
Out[188]//InputForm=
1.0000000000000001278191493200323453724568038240908339267044`36.25561976585499
Here is the actual problem. When we use machine numbers then after 54 iterations there are no significant digits other than zeros in the resulting machine double. That is to say, our size restriction on the numbers is the cause.
The reason is not too mysterious. Call the resulting value 1+eps. Then we have (1+eps)^(2^54) equal (to close approximation) to 10. A second order expansion then shows eps must be smaller than machine epsilon.
First[Select[
eps /. N[Solve[Sum[eps^j*Binomial[2^54, j], {j, 2}] == 9, eps]],
Head[#] === Real && # > 0 &]]]
Out[237]//InputForm=
1.864563472253985*^-16
Out[235]= 2.22045*10^-16
Daniel Lichtblau
Wolfram Research
在上面扔
N[x, 500]
就像试图从岩石中挤出水一样。上面的计算是在机器精度下完成的,速度非常快。如果您愿意放弃速度,您可以利用 Mathematica 的任意精度算术指定输入值的非机器精度。可以使用“反引号”来执行此操作(如下例所示),或者您可以使用
SetPrecision
或SetAccuracy
。这里我将指定输入是10到20位精度的数字。正如您所看到的,您不需要使用
InputForm
,因为 Mathematica 会自动将任意精度的数字打印到尽可能多的位置。如果您确实使用
InputForm
或FullForm
,您将看到一个反引号,然后是一个数字,这是该数字的当前精度。Throwing
N[x, 500]
on this is like trying to squeeze water from a rock.The calculations above are done in machine precision, which is very fast. If you are willing to give up speed, you can utilize Mathematica's arbitrary precision arithmetic by specifying a non-machine precision on the input values. The "backtick" can be used to do this (as in the example below) or you can use
SetPrecision
orSetAccuracy
. Here I will specify that the input is the number 10 up to 20 digits of precision.As you can see you do not need to use
InputForm
as Mathematica will automatically print arbitrary-precision numbers to as many places as it accurately can.If you do use
InputForm
orFullForm
you will see a backtick and then a number, which is the current precision of that number.