Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # BISECTION METHOD
- # Aim - TO IMPLEMENT BISECTION METHOD USING JUPYTER NOTEBOOK
- from math import log, ceil
- x=0
- def bisec(x):
- func = (x**3)-(4*x)-9
- return func
- a=2
- b=3
- err = 0.02
- c1=(a+b)/2
- print(c1)
- c2=0
- n= (log(b-a)-log(err))/log(2)
- print(n)
- i=0
- while i<ceil(n):
- # print("c1 b4= ",c1)
- # print("c2 b4= ",c2)
- # print("a b4 = ",a)
- # print("b b4 = ",b)
- if bisec(b)*bisec(c1)<0:
- c2=c1
- a=c1
- print("a becomes c")
- elif bisec(a)*bisec(c1)<0:
- c2=c1
- b=c1
- print("b becomes a")
- print("c1 af= ",c1)
- # print("c2 af= ",c2)
- # print("a af = ",a)
- # print("b af = ",b)
- print("i = ",i)
- c1=(a+b)/2
- i+=1
- print("Root is - ",c1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement