Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import scipy.interpolate
- import scipy.integrate
- from scipy.optimize import minimize
- def func(x):
- y=3*x*x+2*x
- return y
- print func(4)
- def minimize_own(x):
- dx=0.1
- eps=1e-6
- x0=5
- while (dx > eps):
- f_left =func(x0- dx)
- f_right = func(x0+ dx)
- f_midle = func(x0)
- if (f_left< f_midle):
- x0=x0-dx
- elif(f_right< f_midle):
- x0=x0+dx
- else:
- dx*=0.5
- print x0,dx
- #print minimize(3)
- res = minimize(func, (5))
- print res.x
- xar=np.arange(-10,10,0.01)
- plt.plot(xar, func(xar))
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement