import sympy as sp
import sys
import datetime
import decimal
start_time = datetime.datetime.now()
x = sp.symbols('x')
a = 1234123412341234
f_x = 1/x - a
fp_x = sp.diff(f_x) # 미분
x_init = sys.float_info.min # 2.2250738585072014e-308
Tolerance = 1e-6
x_tmp = x_init
while True:
a = f_x.subs(x,x_tmp)
b = fp_x.subs(x,x_tmp)
x_numeric = (x_tmp) - (a/b)
NR_error = f_x.subs(x, x_numeric)
if abs(NR_error) <= Tolerance :
print(x_tmp)
break
# x_numeric = x_tmp
x_tmp = x_numeric
# result = x_tmp * bc
print('num : ' , x_numeric)
end_time = datetime.datetime.now()
time = end_time - start_time
ms_elapsed_time = time.microseconds / 1000
print(ms_elapsed_time)
I made newton-raphson method with python. Is there any way to make it without using '/'? (I have considered making it with bit shift but a heard that bit shift can only work with integers.)