Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import matplotlib.pyplot as plt
- def function(x):
- return 0.93*x**5 - 0.71*x**4 - 0.53*x**3 + 2.1*x**2 - 10.5
- def dihotom(a, b, count):
- c = (a + b)/2
- if count == 0:
- return c
- else:
- if function(a)*function(c) < 0:
- return dihotom(a, c, count - 1)
- if function(a)*function(c) > 0:
- return dihotom(c, b, count - 1)
- a = 0
- b = 10
- n = 10
- key = 1
- while key:
- marker = function(a) * function(b)
- if marker > 0:
- print("May be you haven't root")
- print("Do you want change a and b? ")
- input(a)
- input(b)
- marker = function(a) * function(b)
- if marker < 0:
- key = 0
- c = dihotom(a, b, n)
- print('root = ', c)
- print('function(root) = ', function(c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement