简体   繁体   中英

How to fit exponential function with python

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM