Advertisement
Guest User

bisec

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1.  
  2. def f(x):
  3.     return x**5 - x**3 + 3*x - 5
  4.  
  5. LIMIT = 50
  6. EPSILON = 10**-5
  7. a = 1
  8. b = 2
  9. c = (a+b)/2
  10. qt = 1
  11.  
  12. while (qt < LIMIT and f(a)*f(b) < 0 and not(-EPSILON <= f(c) <= EPSILON)):
  13.     c = (a+b)/2
  14.     qt += 1
  15.     if (f(a) * f(c) > 0):
  16.         a = c
  17.     else:
  18.         b = c
  19. print(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement