to write a python program to find the square root of a number by newton's medhod
Answers
Answered by
0
def newton_method(number, number_iters = 500):
a = float(number) # number to get square root of
for i in range(number_iters): # iteration number
number = 0.5 * (number + a / number) # update
# x_(n+1) = 0.5 * (x_n +a / x_n)
return number
print newton_method(9)
# Output: 3
print newton_method(2)
# Output: 1.41421356237
Similar questions
Social Sciences,
6 months ago
Science,
6 months ago
Social Sciences,
6 months ago
Physics,
1 year ago
English,
1 year ago