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