Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # high precision square root
- # Newton's method
- # Juhani Kaukoranta 20.6.2018
- import math
- from decimal import *
- def Newton(x,precision) :
- '''high precision square root'''
- getcontext().prec=precision
- x0 = Decimal(1)
- for n in range (0,70):
- x1 = (x0 + Decimal(x)/x0)/Decimal(2)
- x0 = x1
- return(x0)
- a = input("Give number from which to get square root ")
- x = float(a)
- precision = int(input("How many digits precision, f.eq 100 "))
- print("sqrt(",a,") = ",Newton(x,precision))
Advertisement
Add Comment
Please, Sign In to add comment