You are on page 1of 2

Department of Civil Engineering

Indian Institute of Technology Bombay

CE-603 Numerical Methods


September 7, 2020

Homework- 2 Solution

(1) Program file: provided separately.

(2) Scatter plot of the function: See figures on next page.

(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

the uploaded model solution and see it for yourself.


Part (a)- x = 0 to 2 in steps of 0.01
1

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

You might also like