- in just the same way that you cannot write 1/3 exactly using a finite decimal fraction,
- and pi cannot be written with a finite number of digits in any integer base...
Is this Matlab bug or error? anyone who can help?
2 次查看(过去 30 天)
显示 更早的评论
I'm using Matlab to solve some problems.
and I realized sth went wrong
that is like this
stepsize =0.05;
theta = (0:-stepsize:-180+stepsize)*pi/180;
%I'm looking for -90 degree
find(theta == -90*pi/180)
the answer is
ans =
1×0 empty double row vector
What's wrong with me??
2 个评论
Stephen23
2018-2-15
编辑:Stephen23
2018-2-15
The reason is because those numbers are stored on your computer as finite binary numbers called floating point numbers, and they cannot represent exactly those values:
Your code tests for equivalence of floating point numbers, which is always unreliable. You need to change your algorithm to take into account floating point error:
etc, etc, etc
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!