Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. import math
  2.  
  3. delta = 1e-6
  4.  
  5. def f(x): return 2 * 0.26459 * x + 0.89861 - math.cosh(x)
  6.  
  7. def bisection_method(a, b):
  8.     i = 0
  9.     while abs(b - a) > 2 * delta:
  10.         z = 0.5 * (a + b)
  11.         if f(a) * f(z) < 0:
  12.             b = z
  13.         else:
  14.             a = z
  15.         i += 1
  16.     return (a + b) / 2.0
  17.  
  18. print "first point - %f" % bisection_method(0.0, 0.5)
  19. print "second point - %f" % bisection_method(0.5, 1.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement