Reputation: 45
I am new to python and I am trying to learn how to plot and fit data. I have an empeirical formula for describing the function y(x) and i want to fit it to an exponential of the form : y = a* x ^ b
I am using numpy.arrays but i am not sure numpy.polyfit is usefull here because i do not want to fit with high order polynomials, neither exponentials of the form : y = a * e ^ (b*x).
Can you please suggest a way to do this?
my function is this one, here written as y (E_n):
E_n = np.linspace(1, 10**6, 10**6)
y= 0.018*(E_n**(-2.7)) * (1/(1+(2.77*cos(45)*E_n/115)) + 0.367/(1+(1.18*cos(45)*E_n/850)))
Thank you
Upvotes: 1
Views: 934
Reputation: 1744
Consider using scipy.optimize.curve_fit
. Define a function of the form you desire, pass it to the function. Read the linked documentation well. In many cases, you may need to pass chosen initial values for the parameters. curve_fit
takes all of them to be 1
by default, and this might not yield desirable results.
Upvotes: 1