Question
2. On slides 13 and 14 of the file MIT6_0001F16_Lec3 , we discussed about an algorithm (or pseudo code) that computes the exact cube root
2. On slides 13 and 14 of the file MIT6_0001F16_Lec3, we discussed about an algorithm (or pseudo code) that computes the exact cube root of a number. With an initial guess, compute the exact cube root of the following numbers:
a) 280
b) -179
c) -321
Make sure that the guesses which you give are not closer than 10%. Of the individual numbers in a), b) c). Find how many iterations you need to arrive at the exact square root. Also find out if any of the square root computations may diverge (you need infinite number of iterations or you may not arrive at the exact square root and may go off-track).
GUESS-AND-CHECK - cube root cube = 8 for guess in range (cube+1): if guess**3 == cube: print("Cube root of", cube, "is", guess) 6.0001 LECTURE 3 13 GUESS-AND-CHECK cube root cube = 8 for guess in range (abs (cube) +1): if guess**3 >= abs(cube) : break if guess**3 != abs(cube) : print (cube, 'is not a perfect cube') else: if cube = abs(cube) : break if guess**3 != abs(cube) : print (cube, 'is not a perfect cube') else: if cube
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