Task 4 Error in FinitePrecision Computers 5 pts Enter the fo
Task 4: Error in Finite-Precision Computers (5 pts) Enter the following code into the command window of MatLab. format long e; (0.6 + 0.6 + 0.6) - 1.8 Copy the output into a document editor of your choice, exporting it as file a2task4.pdf. In this file, also answer these questions: Is this a result you would expect from the perspective of mathematics? Explain why the computer gave you this result. (Note: after executing the format command given above, all command window display information for numerical values will look something like this: 1.402000000000000e+001. To get it back to a normal single-precision output, type format in the command window prompt and press enter. For more information on this MatLab command, type help format into the command window.)
Task 4: Error in Finite-Precision Computers (5 pts) Enter the following code into the command window of MatLab. format long e, (0.6 0.6 0.6) 1.8 Copy the output into a document editor of your choice, exporting it as file a2tas In this file, also answer these questions: Is this a result you would expect from the perspective of mathematics? Explain why the computer gave you this result. (Note: after executing the format command given above, all command window display information for numerical values will look something like this 1.402000000000000e+001. To get it back to a normal single-precision output, type format in the command window prompt and press enter. For more information on this MatLab command, type help format into the command window.)Solution
When we execute the commands,
format long e;
(0.6+0.6+0.6)-1.8
We get the following result:
-2.22044604925031e-16
The keyword format changes the output, to the appropriate class needed. The class it has to be changed is given as the type, which follows the format keyword.
If we would just execute:
(0.6+0.6+0.6)-1.8
We would get the result as
-2.2204e-16
As we can see the precision has been changed according to the type. Here type is \"long e\", which can be described as a floating point format, with 15 digits.
In the prespective of mathematics, we can visualize the following result,
(6/10 + 6/10 + 6/10) - 18/10
Which is equal to zero. But in our case, 6/10 can be rounded off number. Most decimal fractions cannot be represented exactly as binary fractions. Hence, an approximation of the actual decimal number is actually stored in the machine.
The problem is easier to understand at first in base 10. Consider the fraction 2/3. You can approximate that as a base 10 fraction:
or, better,
or, better,
and so on. No matter how many digits you’re willing to write down, the result will never be exactly 2/3, but will be an increasingly better approximation of 1/3.
In the same way, no matter how many base 2 digits you’re willing to use, the decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base 2, 1/10 is the infinitely repeating fraction
Therefore, we get the result as above.
