khaiwen1111

optimize trigo

Dec 5th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. from scipy import optimize
  2.  
  3. def f(x, a, b):
  4. return a*np.sin(b*np.pi*x)
  5. p = [5, 5]
  6. x = np.linspace(0, 1, 30)
  7. y = f(x, *p) + .5*np.random.normal(size=len(x))
  8. plt.plot(x, y, "or")
  9.  
  10. popt, pcov=optimize.curve_fit(f,x,y,p0=p)
  11. xn=np.linspace(0,1,100)
  12. plt.plot(xn,f(xn,*popt))
Add Comment
Please, Sign In to add comment