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!