Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from math import sqrt
- # Get Input from User (number)
- number = 16
- mathlibresult = sqrt(number)
- iteration = 1
- newguess = number/2
- difference = newguess - mathlibresult
- while (difference > abs(1e-10)):
- print('Iteration: ', iteration, ' Guess: ', newguess, ' Difference: ', difference)
- oldguess = newguess
- newguess = 0.5 * (oldguess + number/oldguess)
- iteration = iteration + 1
- finaldifference = difference
- difference = newguess - mathlibresult
- print('The square root from the math lib is: ', mathlibresult)
- print('The difference between math lib and Newton method is ', finaldifference)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement