Ask Question

Convert Newton's method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of the square root should be passed as a second argument to the function.) An example of the program

+4
Answers (1)
  1. 16 August, 05:00
    0
    import math

    tolerance=0.00001

    approximation=1.0

    x = float (input ("Enter a positive number: "))

    def newton (number, approximation):

    approximation = (approximation+number/approximation) / 2

    difference_value = abs (number-approximation**2)

    if difference_value< = tolerance:

    return approximation

    else:

    return newton (number, approximation)

    print ("The approximation of program = ", newton (x, approximation))

    print ("The approximation of Python = ", math. sqrt (x))

    Explanation:

    Create a recursive function called newton that calls itself again and again to approximate square root for the newton technique. Apply the formulas to find the estimate value and the difference value. Check whether the difference_value is less than the tolerance value and then return the value of approximation else make a recursive call to the newton function by passing the user input and the new approximation value. Finally display all the results using the print statement.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Convert Newton's method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of the square ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers