Question: ANSWER THE FOLLOWING QUESTION IN PYTHON #!/usr/bin/python3 import unittest # -------------------------------------------------------------- def bisection2(x, epsilon): ''' Assume: x, epsilon are floating point numbers and epsilon >

ANSWER THE FOLLOWING QUESTION IN PYTHON

#!/usr/bin/python3

import unittest

# --------------------------------------------------------------

def bisection2(x, epsilon):

'''

Assume: x, epsilon are floating point numbers and epsilon > 0

Use bisection search to find the following solution of y such that

x**3 - epsilon <= y ** 3 - 1 <= x**3 + epsilon

Note: You must use bisection search to implement the function.

'''

# YOUR CODE GOES HERE

# YOUR CODE GOES ABOVE HERE

pass

# --------------------------------------------------------------

# The Testing

# --------------------------------------------------------------

class myTests(unittest.TestCase):

def test1(self):

x, epsilon = -1, 0.001

y = bisection2(x, epsilon)

if y == None:

error = 10*epsilon

else:

error = abs(y ** 3 - (x**3 + 1))

self.assertTrue(error <= epsilon)

self.assertFalse(error <= epsilon / 1000)

def test2(self):

x, epsilon = -0.8, 0.001

y = bisection2(x, epsilon)

if y == None:

error = 10*epsilon

else:

error = abs(y ** 3 - (x**3 + 1))

self.assertTrue(error <= epsilon)

self.assertFalse(error <= epsilon / 1000)

def test3(self):

x, epsilon = 10.2, 0.001

y = bisection2(x, epsilon)

if y == None:

error = 10*epsilon

else:

error = abs(y ** 3 - (x**3 + 1))

self.assertTrue(error <= epsilon)

self.assertFalse(error <= epsilon / 1000)

def test4(self):

x, epsilon = -1.1, 0.001

y = bisection2(x, epsilon)

if y == None:

error = 10*epsilon

else:

error = abs(y ** 3 - (x**3 + 1))

self.assertTrue(error <= epsilon)

self.assertFalse(error <= epsilon / 1000)

def test5(self):

x, epsilon = -1.2, 0.001

y = bisection2(x, epsilon)

if y == None:

error = 10*epsilon

else:

error = abs(y ** 3 - (x**3 + 1))

self.assertTrue(error <= epsilon)

self.assertFalse(error <= epsilon / 1000)

if __name__ == '__main__':

unittest.main(exit=True)

# --------------------------------------------------------------

# The End

# --------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!