Guest User

Untitled

a guest
Apr 10th, 2020
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def NRroot(x,f,dfdx):
  2.     x_val = [0]
  3.     x_diff = 1
  4.     counter = 0
  5.  
  6.     while True:
  7.         x = x-f(x)/dfdx(x)
  8.         x_val.append(x)
  9.         x_diff = x_val[len(x_val)-1] - x_val[len(x_val)-2]
  10.         if x_diff > 10**(-6):
  11.             return x_val[:-1]
  12.  
  13.         print([(counter,x,x_diff)])
  14.         counter += 1
  15.     return x_val
RAW Paste Data