My script sees the value 2 different then 2.0000 which is a problem
Ältere Kommentare anzeigen
hello, i am facing a problem in my script, where MATLAB is seeing the value A=2.000 > B=2 . i have checked the value A to see if it belongs to a value slightly larger then 2 by applying
floor(A) and ceil(A) which both give a result of 2.
what is the problem in your opinion and how could i fix it? Thank you!
Akzeptierte Antwort
Weitere Antworten (1)
Sayyed Ahmad
am 19 Jun. 2018
Bearbeitet: Sayyed Ahmad
am 19 Jun. 2018
Look at Operator Precedence in matlab.
A=2000;
B=2;
C=A>B;
4 Kommentare
Ibrahim DAWI
am 19 Jun. 2018
Guillaume
am 19 Jun. 2018
Sayyed Ahmad's comment mistakenly posted as an answer moved here. Please use comment on this Answer instead of starting a new answer.
you have to look inside your function to find the solution.
This codes will simulate your function output values
a=2
b=2-eps
a==b
answer:
a =
2
b =
2.0000
ans =
logical
0
Dennis
am 19 Jun. 2018
try:
if abs(temp_distance(9)-optimal_distance(9))<0.001
Guillaume
am 19 Jun. 2018
The tolerance (the 0.001, see discussion in my answer) needs to be defined appropriately for the magnitude of the numbers compared and the possible accumulated error of the calculations that produced these numbers.
As we don't know anything about these calculations, we can't be sure of anything but if 0.001 out of 2 is around the magnitude of the accumulated error I'd say that you've got big problems. It is most likely that a smaller tolerance would be more appropriate.
Kategorien
Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!