Elements From a Matrix A bit Off
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
I am a new user of Matlab and I am sure there must be a good reason for this. Here are the code and output: >> a=[0:0.1:0.5]; >> b=0.5-a; >> [a(2) b(5)]
ans =
0.1 0.1
The two numbers look the same in this case. However, when I checked: >> a(2)==b(5)
ans =
0
And
>> a(2)-b(5)
ans =
2.7756e-017
They are actually slightly off. Does anyone know why?
Also, how can I prevent the unwanted consequences from using elements from the matrix, i.e. b(5) is actually not exactly 0.1? Right now, I am just rounding it, which woudl be a bit annoying from time to time. Hope there are better ways to do this.
Cheers!
Fred
0 个评论
回答(1 个)
此问题已关闭。
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!