Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def fun(x):
- return ((x*x*x)+(2*(x**2))+(x)-1)
- def fun1(x):
- return ((3*(x**2))+(4*x)+1)
- def newton(ite,pre_x):
- while(ite>=1):
- a=fun(pre_x)
- b=fun1(pre_x)
- c=(a*1.0)/(b*1.0)
- x=pre_x-c
- #print a,b,c,x
- error=abs(((x-pre_x)/x)*100)
- pre_x=x
- print x,error
- ite-=1
- return 0
- def main():
- xl=0
- xr=0.11
- ite=5
- #print fun(0)
- #print fun(.11)
- newton(5,0)
- return 0
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement