Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import math
  2.  
  3.  
  4. def bisect(function, left, right, error):
  5. while right - left > error:
  6. if function(left) == 0:
  7. return left
  8. if function(right) == 0:
  9. return right
  10.  
  11. middle = (left + right) / 2
  12. if function(left) * function(middle) < 0:
  13. right = middle
  14. else:
  15. left = middle
  16. return left
  17.  
  18.  
  19. def f1(x):
  20. return x ** 3 - x ** 2 - 2 * x
  21.  
  22.  
  23. def f2(x):
  24. return (x + 1) * math.log10(x) - x ** 0.75
  25.  
  26.  
  27. print(bisect(f1, 1, 4, 0.000001))
  28. print(bisect(f2, 1, 4, 0.000001))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement