scipy拟合中的极限索引值

2024-06-12 21:36:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图拟合以下数据

tau = [0.0001, 0.0004, 0.0006, 0.0008, 0.001, 0.0015, 0.002, 0.004, 0.006, 0.008, 0.01, 0.05, 0.1, 0.2, 0.5, 0.6, 0.8, 1.0, 1.5, 2.0, 4.0, 6.0, 8.0, 10.0]
tet = [1.000000000, 0.993790739, 0.965602604, 0.924802378, 0.88010508, 0.778684048, 0.702773729, 0.569882533, 0.544103907, 0.54709633, 0.547347558, 0.543859156, 0.504348651, 0.691909732, 0.351717086, 0.405861814, 0.340536768, 0.301032851, 0.192656835, 0.188915355, 0.100207658, 0.059809495, 0.035968302, 0.024147687]

用一般公式求和

f(x) = $\sum_{i=1}^{n} a_i* exp^{-x/ti}$

我是单独做的,我确信我可以用for函数或者类似的东西来做,但是我不知道怎么做。就这样了

def fitfunc_1(x, a, t1):
  return a * np.exp(- x / t1)

popt_tet_1, pcov = curve_fit(fitfunc_1, data['tau'], data['tet'], maxfev=10000, bounds = (0.0, np.inf))

def fitfunc_2(x, a, t1, b, t2):
  return a * np.exp(- x / t1) + b * np.exp(- x / t2)

popt_tet_2, pcov = curve_fit(fitfunc_2, data['tau'], data['tet'], maxfev=10000, bounds = (0.0, np.inf))

def fitfunc_3(x, a, t1, b, t2, c, t3):
  return a * np.exp(- x / t1) + b * np.exp(- x / t2) + c * np.exp(- x / t3)

popt_tet_3, pcov = curve_fit(fitfunc_3, data['tau'], data['tet'], maxfev=10000, bounds = (0.0, np.inf))

但是,我需要确保a_I索引a、b和c的总和大约为1。意思是a~1,a+b~1,a+b+c~1

有没有办法这样限制scipy的拟合函数

对不起,我想我的问题是noob


Tags: datareturndefnpfitt1curvebounds
1条回答
网友
1楼 · 发布于 2024-06-12 21:36:17

我尝试将数据拟合为两个指数的和,也拟合为三个指数的和。在这两种情况下,配件仅在部分范围内正确,而在整个范围内不正确。在横坐标轴上用对数标度绘制实验点的困难是可以理解的

enter image description here

模式的形状更像是逻辑函数的和,而不是指数函数的和

这表明总和的每一项可能都在以下表格中:

enter image description here

enter image description here

因此,要安装的整个功能是:

enter image description here

enter image description here

注:以上为初步研究,旨在找到一种方便的功能。上述参数数值仅为经验近似值。为了得到更好的拟合,仍然需要使用迭代演算中的非线性回归来计算参数。开始迭代过程的初始值可以是上述参数值

相关问题 更多 >