正确使用位置 [英] Using Position correctly
本文介绍了正确使用位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 mma 帮助文档中 Position
, 以下列在可能的问题"下
In the mma help docs for Position
, the following is listed under "Possible Issues"
In[1]:= Position[Range[-1, 1, 0.05], 0.1]
Out[1]= {}
虽然没有给出解释.为什么会发生这种情况?那么如果我真的需要在Range[-1,1,0.05]
中找到0.1
的位置,我该怎么做?
There is no explanation given though. Why does this happen? So if I really need to find the position of 0.1
in Range[-1,1,0.05]
, how do I do it?
推荐答案
这是一个数值精度问题:Range
中的 0.1 在内部与输入的 0.1 不同.正常的解决方法这是为了与 Equal
而不是隐含的 SameQ
进行比较.
It is a numeric precision issue: 0.1 in the Range
is not internally the same as 0.1 typed in. The normal way to resolve this is to compare with Equal
rather than the implicit SameQ
.
Position[Range[-1, 1, 0.05], x_ /; x == 0.1]
这篇关于正确使用位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文