Reference no: EM132174800
number by successive approximation...
Using Python language:
Programming Project 1: Square root of a number by successive approximations
In this program you should develop and write your own algorithm for computing square roots. One way to approach this is by guessing and testing until a good approximation is found. There are a variety of schemes such as linearly guessing the values or perhaps by halving approximations until an approximation is found within the acceptable bounds of error.
In this exercise we will use the guessing and testing approach. For this approach we will use Newton's method of establishing our next guess.
Given a current guess, guess, if this guess is not within 0.01 of the value calculated by a call to our math library, math.sqrt(x) we should calculate the next guess as follows:
guess = (guess + (x/guess))/2 (1)
While you are free to implement this anyway you choose the following might be of some help:
Input a value, x, for which you plan to estimate the square root.
Calculate the math library solution to the square root problem, sqrtx = math.sqrt(x).
Guess at an initial value for a square root of x. For example, guess = x / 2.
If the quess is within 0.01 of the value calculated by a call to math.sqrt STOP and print out the result.
Otherwise calculate a new quess using the equation given above and test it again. Repeat this process until guess is within 0.01 of the value determined by a call to math.sqrt.
Implement your program in such a manner that after the solution is printed to the screen it loops back and asks for another value to determine the square root of. We can terminate our program using a Ctrl+C sequence in this particular assignment.