如何用python拟合指数函数?

问题描述 投票:0回答:1

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

我使用numpy.arrays,但我不确定numpy.polyfit在这里是否有用,因为我不想用高阶多项式来拟合,也不想用以下形式的指数:y = a * e ^ (b*x)。

你能不能给我一个建议?

我的函数是这个,这里写成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)))

谢谢你的建议

python numpy curve-fitting
1个回答
0
投票

考虑使用 scipy.optimize.curve_fit. 定义一个你想要的形式的函数,把它传给函数。好好阅读链接的文档。在许多情况下,你可能需要为参数传递选定的初始值。curve_fit 将所有的参数都取为 1 默认情况下,这可能不会产生理想的结果。

© www.soinside.com 2019 - 2024. All rights reserved.