Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago