In: Advanced Math
1. Let g(s) = √ s. Find a simple function f so that f(g(s)) = 0. Hint: see Methods of computing square roots on Wikipedia. Use Newton’s method to estimate √ 2. Start with 3 different (and interesting) initial values of your choice and report the number of iterations it takes to obtain an accuracy of at least 4 digits.
In python.
#Python code
import math
def func(x,S):
return (math.pow(x,2)-S)
def diff_func(x,S):
return (2*x)
S= int(input('Enter the number for which square needed to be found:
'))
x= []
x.append(int(input('Enter initial approximation value: ')))
i=0
count=0
while(True):
f= func(x[i],S)
df= diff_func(x[i],S)
x.append(round(x[i]-(f/df),4))
if x[i+1]==x[i]:
break
count+=1
i+=1
print('Square root of ' + str(S) + ' is ' + str(x[i]))
print('Total number of iterations that took to achieve the accuracy
of 4 digits is ' + str(count))
Output 1:
Enter the number for which square needed to be found: 24
Enter initial approximation value: 5
Square root of 24 is 4.8989
Total number of iterations that took to achieve the accuracy of 4 digits is 2
Output 2:
Enter the number for which square needed to be found: 73
Enter initial approximation value: 9
Square root of 73 is 8.5440
Total number of iterations that took to achieve the accuracy of 4 digits is 2
Output 3:
Enter the number for which square needed to be found: 141
Enter initial approximation value: 11
Square root of 141 is 11.8743
Total number of iterations that took to achieve the accuracy of 4 digits is 3