Use position correctly

In mma help docs for Position , under the "Possible Problems" section, it says

 In[1]:= Position[Range[-1, 1, 0.05], 0.1] Out[1]= {} 

However, no explanation is given. Why is this happening? So if I really need to find position 0.1 in Range[-1,1,0.05] , how to do this?

+6
source share
1 answer

This is a problem with numerical precision: 0.1 in Range not internally the same as 0.1 entered. The usual way to resolve this is to compare with Equal , not with the implicit SameQ .

 Position[Range[-1, 1, 0.05], x_ /; x == 0.1] 
+9
source

Source: https://habr.com/ru/post/886431/


All Articles