Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy import optimize
- def f(x, a, b):
- return a*np.sin(b*np.pi*x)
- p = [5, 5]
- x = np.linspace(0, 1, 30)
- y = f(x, *p) + .5*np.random.normal(size=len(x))
- plt.plot(x, y, "or")
- popt, pcov=optimize.curve_fit(f,x,y,p0=p)
- xn=np.linspace(0,1,100)
- plt.plot(xn,f(xn,*popt))
Add Comment
Please, Sign In to add comment