使用分段功能进行复杂的曲线拟合

时间:2019-11-04 05:35:28

标签: python scipy curve-fitting astronomy scipy-optimize

这是我的第一篇文章,所以如果我错过了重要信息,请告诉我。我正在尝试对两个参数进行曲线拟合。基本上,我们得到z_array(红移)m_B_eff(量级)。曲线拟合需要输出OmegaMOmegaA的拟合值。

数组如下:

z_array = [
    0.458, 0.354, 0.425, 0.374, 0.42, 0.372, 0.378, 0.453, 0.465, 0.498,
    0.655, 0.4, 0.615, 0.48, 0.45, 0.388, 0.57, 0.49, 0.495, 0.656, 0.828,
    0.45, 0.43, 0.58, 0.763, 0.526, 0.172, 0.619, 0.592, 0.55, 0.18, 0.374,
    0.472, 0.43, 0.657, 0.612, 0.32, 0.579, 0.45, 0.581, 0.416, 0.83, 0.03, 
    0.05, 0.026, 0.075, 0.026, 0.014, 0.101, 0.02, 0.036, 0.045, 0.043,
    0.018, 0.079, 0.088, 0.063, 0.071, 0.052, 0.05
]

m_B_eff = [
    23.11, 22.38, 22.13, 21.72, 22.55, 22.26, 22.58, 23.17, 23.33,
    23.71, 23.27, 22.36, 23.19, 22.96, 22.51, 22.65, 23.27, 23.1,
    22.83, 23.57, 24.65, 23.17, 23.13, 23.46, 24.47, 23.15, 20.17,
    23.8, 24.42, 23.51, 20.43, 23.52, 23.11, 22.57, 23.83, 23.69,
    21.86, 23.48, 22.83, 23.09, 22.57, 24.32, 16.26, 17.63, 16.08,
    18.43, 16.28, 14.47, 19.16, 15.18, 16.66, 17.61, 17.19, 15.61,
    18.27, 19.28, 18.24, 18.33, 17.54, 17.69
]

在一次尝试中,我尝试将z_array的值输入到函数中,以获取scipy来计算OmegaA和{的最佳拟合参数{1}}尽管如此,两者的输出都在10 ^ 16的数量级上……它们应该在一个单位的数量级上。在OmegaM试图拟合它们时显示这些值,这表明这两个omega值的大小都爆炸了

scipy

宇宙学参数:from scipy.optimize import curve_fit def func2(x, OmegaA, OmegaM): resultArr = [] LfuncArr = [] K = 0 for r in range(len(x)): if OmegaM + OmegaA == 1: K = 1 LfuncArr.append(np.sqrt(np.abs(K))*(integrate.quad(lambda y: (((1+y)**2)*(1+y*OmegaM)-(2+y)*OmegaA*y)**-0.5, 0, x[r],limit=10000)[0])) elif OmegaM + OmegaA > 1: K = 1-OmegaM-OmegaA LfuncArr.append(np.sin(np.sqrt(np.abs(K))*(integrate.quad(lambda y: (((1+y)**2)*(1+y*OmegaM)-(2+y)*OmegaA*y)**-0.5, 0, x[r],limit=10000)[0]))) elif OmegaM + OmegaA < 1: K = 1-OmegaM-OmegaA LfuncArr.append(np.sinh(np.sqrt(np.abs(K))*(integrate.quad(lambda y: (((1+y)**2)*(1+y*OmegaM)-(2+y)*OmegaA*y)**-0.5, 0, x[r],limit=10000)[0]))) resultArr.append((5*np.log10(c*(1+x[r])/np.sqrt(np.abs(K)) * LfuncArr[r]) + 17.931)) return resultArr plt.plot p0 = 0.5, 0.5 popt2, pcov2 = curve_fit(func2, z_array, m_B_eff, p0, maxfev=50000) OmegaA的预期输出拟合值处于统一的数量级。 OmegaMK将根据分段函数进行定义

有关我要绘制的函数的更多信息,请参见:https://iopscience.iop.org/article/10.1086/304265/pdf第566页。

0 个答案:

没有答案