Question
ANSWER THE FOLLOWING AND PUT THE ANSWER IN THE QUESTION WHERE ITS SUPPOSED TO BE PLEASE: #!/usr/bin/python3 import unittest # -------------------------------------------------------------- def bisection2(x, epsilon): '''
ANSWER THE FOLLOWING AND PUT THE ANSWER IN THE QUESTION WHERE ITS SUPPOSED TO BE PLEASE:
#!/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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started