Hi, I have a funny problem... The simple expression 100*1.1==110 does not give answer 1 but (quite surprisingly) zero...
The point is that the difference 100*1.1-110 is not zero but something like e-14...
I'm wondering if a solution to this problem exists.
Thank you very much!!!

답변 (2개)

Jan
Jan 2011년 5월 9일

1 개 추천

댓글 수: 3

Matt Tearle
Matt Tearle 2011년 5월 9일
I suggest a new MathWorks business model: we give away MATLAB for free, then charge $0.05 every time this question (or a variant thereof) is asked.
Sean de Wolski
Sean de Wolski 2011년 5월 9일
Why don't you just add "intendeq()" to your fuzzy logic toolbox. It's automatically called every time eq() is called and makes a determination if the user ACTUALLY wants things to be equal.
Jan
Jan 2011년 5월 9일
@Matt T: Another business model: We buy MATLAB for some 1000$, spend two weeks to read the documentation, listen 2 years to a professor talking about Applied Numerics, create the FAQ for anyone to read, and train our eloquence by answering 200 questions in CSSM and 30 one here related to floating point arithmetics. Then, and just then, we are in the position to invest further 60 sec from our time to answer the next similar question. (If the keyboard latency would be more bearable, it would have been just 10 seconds to type the single line...).
Most of all I feel with Matteo: He must have thought that MATLAB is such dumb, that it is not able to perform hilarious trivial calculations which are solved by 8 year old children correctly and free of charge. Such experiences can influence the world outlook, they can shake the trust in mathematics and destroy the self-confidence. So:
@Matteo: Don't be frustrated. You are not the first one who asks this question, and you will not be the last one.
@Sean: feature('dwim', 1)

댓글을 달려면 로그인하십시오.

Sean de Wolski
Sean de Wolski 2011년 5월 9일

0 개 추천

The easiest way is to set a tolerance on some criteria for being equal. E.g.
isclose = @(x,y)all(abs(x-y)<(10^-10));
isclose(100*1.1,110)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2011년 5월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by