Professional Documents
Culture Documents
Homework- 2 Solution
(3) Comment:
Contrary to the shape of the plot in part (a), the plot in part (b) does not appear to
be cubic.
In part (b), 'single' data type is unable to represent the true values of the internal
calculations (for example, in single data type, x^3 can not be precisely represented
for x = 0.9999 99) and therefore values of f(x) are erroneous. Due to this, the values
of function are misleading and the program may report spurious roots of the
function.
If same graphs are plotted with 'double' data type (rather than 'single' data type), one
can clearly see the cubic shape of the plot even in part (b). Consider playing with
0.5
0
y
-0.5
-1
0 0.5 1 1.5 2
x
-7
x 10 Part (b)- x = 0.9998 to 1.0002 in steps of 5e-6
2.5
1.5
0.5
y
-0.5
-1
-1.5
0.9998 0.9998 0.9999 0.9999 1 1 1.0001 1.0001 1.0002 1.0002
x