Clear Filters
Clear Filters

Floating-point values give limitations for true-false?

2 views (last 30 days)
Decide if the equation is mathematically true for the variable values provided below.
Implement the equations in MATLAB, and test if they are true in the floating point arithmetic within MATLAB for the variable values provided. (For example, the equation 3 + 7^2 = 5 in matlab would correspond to the command disp(3+7^2==5) and yields, upon execution of the command, the value 0 corresponding to false. This is expected since the equation is not mathematically true.)
Where the MATLAB result differs from the mathematical expectation explain in one or more full sentences why the MATLAB results are different.
The equations to be considered are, with x = 10^7,
1. x^2 + x = x
2. x + x^5 = x
3. x^21/x^6 = x^15
In regards to 3. how come the value is equal to 0 (false) and not equal 1 (true) unless the input of x is less than 10. should it be true or false?
%Matlab program to check True or false of the statements for given values
%OUTPUT where 1 means True, 0 means False
x = 10^7;
aPart1 = x^2+ x
disp(x^2+ x== x)
aPart2 = x+ x^5
disp(x+ x^5== x)
aPart3 = x^21/ x^6
disp(x^21/x^6== x^15)
  1 Comment
Stephen23 on 20 Sep 2021
Edited: Stephen23 on 20 Sep 2021
"In regards to 3. ... should it be true or false?"
That is the entire point of your assignment: to understand that in general floating point arithmetic is not the same as mathematical/symbolic/algebraic arithmetic. Search this forum for "binary floating point", you will find many good explanations (which you can then "explain in one or more full sentences", just as your assignment requests).

Sign in to comment.

Answers (0)





Community Treasure Hunt

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

Start Hunting!