0

我有一个包含一列数值数据的文件,我想将这些数据拟合到应该描述它们的理论函数中。我要查找数据的功能是:


要拟合的参数是 (n,a) 有没有办法使用八度音程或 python 将一组数据拟合到定义的函数?
通常我使用 gnuplot 来做,但由于我必须做更多的数据分析,所以我想学习如何用编程语言来做。谢谢你。

4

2 回答 2

0

八度

Octave 有几个拟合函数。只需在https://octave.sourceforge.io/docs.php上搜索“适合”这个词。

这是一个看起来与您的问题相关的optim包:https ://octave.sourceforge.io/optim/function/nonlin_curvefit.html

于 2021-03-10T10:25:30.653 回答
0

You definitely can. There’s many possibilities, one of the easiest one I can think of is to use a least squares approach (assuming n and a are floating point numbers and not integers). Like this more or less:

from scipy.optimize import curve_fit

def func(x, n, a):
    return x**n / (x**n + a**n)

popt, pcov = curve_fit(func, xdata, ydata)

Where”popt “ contains your optimized n, a parameters. I strongly suggest you plot your xdata, ydata and your fitted function after: depending on the noise on your xdata, ydata sometimes curve_fir can go ballistic.

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

于 2021-03-10T06:32:59.117 回答