Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def function(x):
- return 0.93*x**5 - 0.71*x**4 - 0.53*x**3 + 2.1*x**2 - 10.5
- def dichotomy(a, b, count):
- c = (a + b)/2
- if count == 0 or abs(function(c)) < 0.0001:
- return c
- else:
- if function(a)*function(c) < 0:
- return dichotomy(a, c, count - 1)
- if function(a)*function(c) > 0:
- return dichotomy(c, b, count - 1)
- start = 0
- end = 10
- n = 20
- key = 1
- while key: #interval check
- sign = function(start) * function(end)
- if sign > 0:
- print("May be you haven't root. Please change 'start' and 'end'")
- start = int(input())
- end = int(input())
- sign = function(start) * function(end)
- if sign < 0:
- key = 0
- X = dichotomy(start, end, n)
- print('root = ', X)
- print('function = ', function(X))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement