Matlab gives wrong answer

前端 未结 3 484
小蘑菇
小蘑菇 2020-12-07 02:11

If the following code is executed MATLAB makes a mistake. Can someone verify this?

floor([0.1:0.1:2]/0.01)

So what is the 129 doing here??<

3条回答
  •  粉色の甜心
    2020-12-07 02:43

    it's a rounding approximation brought on by the array construction. The solution would be to add eps:

    floor([0.1:0.1:2]/0.01+ eps([0.1:0.1:2]/0.01))
    

提交回复
热议问题