Advertisement
allekco

1lab

Oct 24th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import math
  2. import matplotlib.pyplot as plt
  3.  
  4.  
  5. def function(x):
  6.     return 0.93*x**5 - 0.71*x**4 - 0.53*x**3 + 2.1*x**2 - 10.5
  7.  
  8.  
  9. def dihotom(a, b, count):
  10.     c = (a + b)/2
  11.     if count == 0:
  12.         return c
  13.     else:
  14.         if function(a)*function(c) < 0:
  15.             return dihotom(a, c, count - 1)
  16.         if function(a)*function(c) > 0:
  17.             return dihotom(c, b, count - 1)
  18.  
  19.  
  20. a = 0
  21. b = 10
  22. n = 10
  23. key = 1
  24. while key:
  25.     marker = function(a) * function(b)
  26.     if marker > 0:
  27.         print("May be you haven't root")
  28.         print("Do you want change a and b? ")
  29.         input(a)
  30.         input(b)
  31.     marker = function(a) * function(b)
  32.     if marker < 0:
  33.             key = 0
  34. c = dihotom(a, b, n)
  35. print('root = ', c)
  36. print('function(root) = ', function(c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement