daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import math
  3.  
  4. def fun(x):
  5.     return ((x*x*x)+(2*(x**2))+(x)-1)
  6.  
  7. def fun1(x):
  8.     return ((3*(x**2))+(4*x)+1)
  9.    
  10.  
  11. def newton(ite,pre_x):
  12.    
  13.     while(ite>=1):
  14.         a=fun(pre_x)
  15.         b=fun1(pre_x)
  16.         c=(a*1.0)/(b*1.0)      
  17.         x=pre_x-c
  18.         #print a,b,c,x
  19.         error=abs(((x-pre_x)/x)*100)
  20.         pre_x=x
  21.         print x,error
  22.         ite-=1
  23.    
  24.                        
  25.     return 0
  26.  
  27. def main():
  28.     xl=0
  29.     xr=0.11
  30.     ite=5
  31.     #print fun(0)
  32.     #print fun(.11)
  33.     newton(5,0)
  34.    
  35.     return 0
  36.  
  37.  
  38. if __name__ == "__main__":
  39.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top