exp 関数のカーブフィットの使い方です。
次のような結果を得ます。
curve_fit03.py
# ! /usr/bin/python
#
# curve_fit03.py
#
# Apr/16/2020
# ------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
# ------------------------------------------------------------------
def exp(xx, aa, bb, dd, pp):
rvalue = 0.0
try:
rvalue = dd * np.exp(aa * xx - bb) + pp
except Exception as ee:
sys.stderr.write("*** error *** in exp ***\n")
sys.stderr.write(str(ee) + "\n")
return rvalue
# ------------------------------------------------------------------
xx = np.array([0,1,2,3,4,5,6,7,8])
yy = np.array([95.0, 100.0, 114.0,134.0,178.0,245.0,312.0,412.0,603.0])
popt, pcov = curve_fit(exp, xx, yy)
plt.figure()
plt.plot(xx, yy, 'ko', label="Original Data")
plt.plot(xx, exp(xx, *popt), 'r-', label="Fitted Curve")
plt.legend()
plt.show()
# ------------------------------------------------------------------