**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- # Newton–Raphson Method : algorithm for finding roots
- # ragulbalaji19
- import math
- def f(x): return pow(math.e,-x) + x * pow(math.e,-x) - 0.5 # function we want to study
- def fprime(x): return -(x * pow(math.e, -x)) # first derivative of said function
- starting = [-0.5,0.0,0.5,3.0,3.449,3.5,5.0,6.0,7.0,10.0,40.0] # some starting points to start the process
- for pt in starting:
- print("starting @",pt)
- ptn = pt
- for i in range(100): # TIMEOUT ARBITRARILY SET AT 100
- ptnold = ptn
- try:
- ptn = ptn - (f(ptn)/fprime(ptn))
- except Exception as e:
- print("DED", e)
- break;
- print(ptn)
- if abs(ptnold - ptn) < 0.0000001:
- print("CONVERGED.")
- break
- print("---\n")

RAW Paste Data