Ask Question
7 February, 06:15

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

+2
Answers (1)
  1. 7 February, 09:35
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers