Matlab Precision
Show older comments
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!!!
Answers (2)
Jan
on 9 May 2011
1 vote
3 Comments
Matt Tearle
on 9 May 2011
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
on 9 May 2011
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
on 9 May 2011
@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
on 9 May 2011
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)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!