Advertisement
Sephinroth

Метод срединной точки (доделать)

Oct 14th, 2020
2,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from scipy.misc import derivative as der
  4.  
  5. def F(x):
  6.     return x**4 + x**2 + x + 1
  7.  
  8. def Par(a, b, eps, x):
  9.     #метод средней точки
  10.     for i in np.arange(a, b, eps/10):
  11.         x.append(i)
  12.     y = [F(i) for i in x]
  13.     x_temp = (a+b)/2
  14.     while abs(der(F(x_temp))) < eps:
  15.         x_temp = (a+b)/2
  16.         if der(F(x_temp)) < 0:
  17.             b = x_temp
  18.         else:
  19.             a = x_temp
  20.     y = [F(i) for i in x]
  21.     plt.plot (x, y)
  22.     plt.grid(True)
  23.     plt.show()
  24.     print("Метод срединной точки: \nx* = ", x_temp, "\ny_min = ", F(x_temp))
  25.  
  26.    
  27. def main():
  28.     a = -1
  29.     b = 0
  30.     eps = 0.01
  31.     x = []
  32.     for i in np.arange(a, b, eps/10):
  33.         x.append(i)
  34.  
  35. if __name__ == "__main__":    
  36.     main()    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement