我想用curve_fit拟合一条复杂曲线,并求出方程中的三个参数,但是运行后程序报错如下
TypeError: 'numpy.float64' object is not callable
代码如下,哪里出错了,我没有找到变量和函数名冲突
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
# a,b,c是需要求出来的三个参数,D,z,ee全都是已知的。
def dfin(x, a, b, c):
return ((a*z**b-30.0)(1.0-np.exp(-np.log(2.0*(x/ee)**c))))
D = 30.0
z = 1.31*10**21
ee = 0.0016*D**0.2709*z**0.1147
# 给出x、y对应坐标
x = [1.29, 1.24, 1.11, 0.97, 0.82, 0.68, 1.07, 0.86, 0.64, 0.52]
x = np.array(x)
num = [15.7, 15.0, 18.2, 18.7, 21.1, 24.5, 15.7, 21.2, 24.8, 31.7]
y = np.array(num)
# 非线性最小二乘法拟合
popt, pcov = curve_fit(dfin, x, y)
# 获取popt里面拟合系数
print(popt)
a = popt[0]
b = popt[1]
c = popt[2]
yvals = dfin(x, a, b, c)
print('系数a:', a)
print('系数b:', b)
print('系数c:', c)
print('系数yvals:', yvals)
# 绘图
plot1 = plt.plot(x, y, 's', label='original values')
plot2 = plt.plot(x, yvals, 'r', label='polyfit values')
plt.xlabel('x')
plt.ylabel('y')
plt.legend(loc=4)
plt.title('curve_fit')
plt.show()