Elements From a Matrix A bit Off
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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
Antworten (1)
Azzi Abdelmalek
am 19 Nov. 2013
0 Stimmen
Diese Frage ist geschlossen.
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!