Ask Question
26 August, 15:16

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

+1
Answers (1)
  1. 26 August, 17:38
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers