# Python应用实现双指数函数及拟合代码实例

```import matplotlib.pyplot as plt

x = ([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5,
0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0])
y = ([0.33, 0.26, 0.18, 0.16, 0.12, 0.09, 0.08, 0.07, 0.06, 0.06,
0.06, 0.07, 0.09, 0.1, 0.15, 0.19, 0.25, 0.36, 0.47, 0.68])

plt.scatter(x, y)
plt.show()```

```import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def double_exp(x, b, c, p, q):
x = np.array(x)
return b*np.exp(p*x) + c*np.exp(q*x)

x = ([0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5,
0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0])
y = ([0.33, 0.26, 0.18, 0.16, 0.12, 0.09, 0.08, 0.07, 0.06, 0.06,
0.06, 0.07, 0.09, 0.1, 0.15, 0.19, 0.25, 0.36, 0.47, 0.68])

popt, pcov = curve_fit(double_exp, x, y, [1, 1, 1, 1])
print(popt)

b = popt[0]
c = popt[1]
p = popt[2]
q = popt[3]

y_fit = double_exp(x, b, c, p, q)

plt.scatter(x, y)
plt.plot(x, y_fit, color='red', linewidth=1.0)

plt.show()```

numpy 库，实现列表转矩阵，得以进行数学运算。matplotlib.pyplot 库，绘制图像。scipy.optimize 库，curve_fit() 函数，使用非线性最小二乘法拟合曲线。curve_fit()popt，拟合结果，在这里指b, c, p, q 的值。povc，该拟合结果对应的协方差。