简体   繁体   English

如何用 python 拟合指数 function

[英]How to fit exponential function with python

I am new to python and I am trying to learn how to plot and fit data.我是 python 的新手,我正在尝试学习如何 plot 和拟合数据。 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我有一个用于描述 function y(x) 的经验公式,我想将其拟合为以下形式的指数: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).我正在使用 numpy.arrays 但我不确定 numpy.polyfit 在这里有用,因为我不想适应高阶多项式,既不适合高阶多项式,也不适合指数形式:

Can you please suggest a way to do this?你能建议一种方法吗?

my function is this one, here written as y (E_n):我的 function 就是这个,这里写成 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 .考虑使用scipy.optimize.curve_fit Define a function of the form you desire, pass it to the function.定义您想要的形式的 function,将其传递给 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.默认情况下, curve_fit将它们全部设为1 ,这可能不会产生理想的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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