0

I am having trouble in creating my own fitting function in python. In particular my problem is the following. I have the following set of data:

vel = [-337, -108, 79, 309, 518, 528, 494, 432, 203, 15, -236, -401, -496]     
phase = [-0.1405, -0.0583, 0.0325, 0.0998, 0.174, 0.231, 0.3079, 0.3699, 0.4388, 0.5008, 0.5698, 0.6371, 0.7276] 


err =  [45.342891308377489, 73.067581785521284, 41.676025292022672, 68.304971952287929, 92.089464137519201, 45.111554097374324, 38.922906106705625, 35.431519418447465, 42.787787783231522, 19.305857846218228, 59.22902735428562, 49.416599841251582, 63.027937055619532]

Where the first array is the y value, the second is the x and the third one contains the error of the y value. I should now create a function of the form

V(\phi) = \gamma + K1*sin(2*pi*\phi) +K2*cos(2*pi*\phi)

to fit the data. The values of the parameters have to be obtained from the best fit.

Any idea on how to do that?

rob
  • 71
  • 1
  • 5
  • It looks like you are trying to do non-linear curve fitting. Here's a relevant example: https://stackoverflow.com/questions/16716302/how-do-i-fit-a-sine-curve-to-my-data-with-pylab-and-numpy – Craig Dec 30 '17 at 17:36
  • You can use [curve_fit](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html) or also [lmfit](https://lmfit.github.io/lmfit-py/) for those tasks. – Cleb Jan 05 '18 at 09:25

0 Answers0