Advertisement
Serafim_

Подсчет миниум и максимум

Apr 11th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy.optimize import minimize
  4. import scipy.interpolate
  5. import scipy.integrate
  6.  
  7.  
  8. def func(x):
  9.     y=3*x*x+2
  10.     return y
  11. print func(4)
  12.  
  13. dx=0.1
  14. eps=1e-5
  15. x_0=5
  16.  
  17. while (dx>eps):
  18.     f_left=func(x_0-dx)
  19.     f_right=func(x_0+dx)
  20.     f_middle=func(x_0)
  21.     if (f_left<f_middle):
  22.         x_0=x_0-dx
  23.  
  24.     elif (f_right<f_middle):
  25.         x_0=x_0+dx
  26.     else:
  27.         dx=dx*0.5
  28.     print x_0,dx
  29.  
  30. xar=np.arange(-10,10,0.01)
  31. plt.plot(xar,func(xar))
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement