Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- # exp(x) - 2x - 2 = 0
- # x3 + 3x - 5
- try:
- a = int(input())
- b = int(input())
- except ValueError:
- raise ValueError('a and b must be integers')
- class SameSigns(Exception):
- pass
- def math_function(x):
- return math.pow(x, 3) - 3 * x - 5
- def math_function2(x):
- return math.exp(x) - 2 * x - 2
- def bisection_method(num1, num2, func):
- if func(num1) * func(num2) >= 0:
- raise SameSigns('f(a) and f(b) must be with different signs')
- middle = 0
- while num2 - num1 >= 0.001:
- middle = (num1 + num2) / 2
- if func(middle) * func(num1) < 0:
- num2 = middle
- else:
- num1 = middle
- if func(middle) == 0.0:
- break
- return f"{middle:.4f}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement