Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. def f(x):
  2.     return x**2 - 5
  3.  
  4. a = int(input())
  5. b = int(input())
  6. e = int(input())
  7.  
  8. x = a
  9. f1 = f(a)
  10. h = b - a
  11.  
  12. while abs(h) > e:
  13.     h = h / 3
  14.  
  15.     x = x + h
  16.     f2 = f(x)
  17.  
  18.     while f1 * f2 > 0:
  19.         x = x + h
  20.         f2 = f(x)
  21.  
  22.     x = x - h
  23.  
  24. x = x - h / 2
  25. f1 = f(x)
  26.  
  27. print(x, f1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement