Square root of a number by newton's method in python


Asked by admin @ in Computers and Technology viewed by 307 People


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

Answered by admin @



Answer:

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.

Similar Questions

How to calculate square root of a number without calculator

Asked by admin @ in Mathematics viewed by 321 persons

Describe how you would estimate the square root of a number that is not a perfect square without using a calculator.

How can we find the square root of a number

Asked by admin @ in Mathematics viewed by 339 persons

How does finding the square root of a number compare to finding the cube root of a number? Use the number 64 in your explanation.

Can you take the square root of a negative number

Asked by admin @ in Mathematics viewed by 348 persons

Why can't we take a square root of a negative number?

Find the square root of 20449 by division method

Asked by admin @ in Math viewed by 292 persons

Find the square root of 20449 by the method of long division

How to draw square root 2 on number line

Asked by admin @ in Math viewed by 400 persons

How to represent root 2 on number line with steps?

Find the square root of 9604 by division method

Asked by admin @ in Math viewed by 492 persons

Find the square root of 9604 by division method

Find the square root of 27225 by division method

Asked by admin @ in Math viewed by 293 persons

Finf the square root of 27225 by division method

Find the square root by long division method 17956

Asked by admin @ in Math viewed by 287 persons

Square root of 17956 by long division method plz anyone help me I have exam tomorrow

Find the square root of 6084 by division method

Asked by admin @ in Math viewed by 321 persons

Find the square root of 6084 by long division method

Find the square root of complex number 3 4i

Asked by admin @ in Math viewed by 297 persons

Find square root of 3-4i

Find the square root of 9025 by division method

Asked by admin @ in Math viewed by 405 persons

Find the square root of 9025 and 7569 by division method

Find the square root of 1764 by division method

Asked by admin @ in Math viewed by 316 persons

Square root of 1764 by division method

Find the square root of 9216 by division method

Asked by admin @ in Math viewed by 291 persons

Find the square root of 9216 by division method.​

Find the square root of 576 by division method

Asked by admin @ in Math viewed by 518 persons

Evaluate square root of 576 by long division method

Find the square root by long division method 1764

Asked by admin @ in Math viewed by 240 persons

Square root of 1764 by division method

Most viewed questions in Computers And Technology


A customer wants to increase the storage capacity by 25gb

Asked by admin @ in Computers and Technology viewed by 4434 persons




Solid yellow line bordering your lane of traffic marks a

Asked by admin @ in Computers and Technology viewed by 610 persons



Which of the following is not a windows utility program

Asked by admin @ in Computers and Technology viewed by 595 persons


When is a wrecker considered to be an emergency vehicle

Asked by admin @ in Computers and Technology viewed by 579 persons


Which operation on a pwc requires more than idle speed

Asked by admin @ in Computers and Technology viewed by 576 persons



Which of the following statements is true of a database

Asked by admin @ in Computers and Technology viewed by 563 persons


Which of the following is not true about an entrepreneur

Asked by admin @ in Computers and Technology viewed by 540 persons


Kitchen gadgets draw a context diagram for the order system

Asked by admin @ in Computers and Technology viewed by 516 persons