scipy解非线性方程组报错TypeError: 'int' object is not callable

scipy解非线性方程组报错TypeError: 'int' object is not callable。网上说是参数和函数重名的缘故，但貌似我的并没有重名，代码如下：

``````from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import root,fsolve

def fun(x):
for i in range(0,len(x)):
x[i] = float(x[i])
fy = np.array([(x[0]*2010**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2010**x[3])+(-75.2303)**2/(x[4]*2010**x[5])-6259)),(x[0]*2011**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2011**x[3])+(-75.2303)**2/(x[4]*2011**x[5])-5958)),(x[0]*2012**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2012**x[3])+(-81.4421)**2/(x[4]*2012**x[5])-2624)),(x[0]*2014**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2014**x[3])+(-75.2303)**2/(x[4]*2014**x[5])-4809)),(x[0]*2015**x[1])*np.exp(-1/2(39.701**2/(x[2]*2015**x[3])+(-84.2187)**2/(x[4]*2015**x[5])-3877)),(x[0]*2017**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2017**x[3])+(-81.4421)**2/(x[4]*2017**x[5])-7381))])
return fy
res_fsolve = fsolve(fun,[1,1,1,1,1,1])
print(res_fsolve)
``````

TypeError Traceback (most recent call last)
in
9 fy = np.array([(x[0]*2010**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2010**x[3])+(-75.2303)**2/(x[4]*2010**x[5])-6259)),(x[0]*2011**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2011**x[3])+(-75.2303)**2/(x[4]*2011**x[5])-5958)),(x[0]*2012**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2012**x[3])+(-81.4421)**2/(x[4]*2012**x[5])-2624)),(x[0]*2014**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2014**x[3])+(-75.2303)**2/(x[4]*2014**x[5])-4809)),(x[0]*2015**x[1])*np.exp(-1/2(39.701**2/(x[2]*2015**x[3])+(-84.2187)**2/(x[4]*2015**x[5])-3877)),(x[0]*2017**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2017**x[3])+(-81.4421)**2/(x[4]*2017**x[5])-7381))])
10 return fy
---> 11 res_fsolve = fsolve(fun,[1,1,1,1,1,1])
12 print(res_fsolve)

c:\users\anton\appdata\local\programs\python\python36\lib\site-packages\scipy\optimize\minpack.py in fsolve(func, x0, args, fprime, full_output, col_deriv, xtol, maxfev, band, epsfcn, factor, diag)
145 'diag': diag}
146
--> 147 res = _root_hybr(func, x0, args, jac=fprime, **options)
148 if full_output:
149 x = res['x']

c:\users\anton\appdata\local\programs\python\python36\lib\site-packages\scipy\optimize\minpack.py in _root_hybr(func, x0, args, jac, col_deriv, xtol, maxfev, band, eps, factor, diag, **unknown_options)
211 if not isinstance(args, tuple):
212 args = (args,)
--> 213 shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
214 if epsfcn is None:
215 epsfcn = finfo(dtype).eps

c:\users\anton\appdata\local\programs\python\python36\lib\site-packages\scipy\optimize\minpack.py in _check_func(checker, argname, thefunc, x0, args, numinputs, output_shape)
24 def _check_func(checker, argname, thefunc, x0, args, numinputs,
25 output_shape=None):
---> 26 res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
27 if (output_shape is not None) and (shape(res) != output_shape):
28 if (output_shape[0] != 1):

in fun(x)
7 for i in range(0,len(x)):
8 x[i] = float(x[i])
----> 9 fy = np.array([(x[0]*2010**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2010**x[3])+(-75.2303)**2/(x[4]*2010**x[5])-6259)),(x[0]*2011**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2011**x[3])+(-75.2303)**2/(x[4]*2011**x[5])-5958)),(x[0]*2012**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2012**x[3])+(-81.4421)**2/(x[4]*2012**x[5])-2624)),(x[0]*2014**x[1])*np.exp(-1/2(39.9612**2/(x[2]*2014**x[3])+(-75.2303)**2/(x[4]*2014**x[5])-4809)),(x[0]*2015**x[1])*np.exp(-1/2(39.701**2/(x[2]*2015**x[3])+(-84.2187)**2/(x[4]*2015**x[5])-3877)),(x[0]*2017**x[1])*np.exp(-1/2(41.3866**2/(x[2]*2017**x[3])+(-81.4421)**2/(x[4]*2017**x[5])-7381))])
10 return fy
11 res_fsolve = fsolve(fun,[1,1,1,1,1,1])

TypeError: 'int' object is not callable

• 写回答

1条回答默认 最新

• 高山听流水 2019-01-31 15:32
关注

我后来发现，是我大意了，在函数里面，np.exp()里面1/2与后面的部分相乘，我把*号省略了。python里面的数字与数字之间的*是不能省略的。

本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

悬赏问题

• ¥15 visionmaster启动失败，提示为“机器不满足授权而被禁用”
• ¥50 用logisim设计16位单时钟周期cpu
• ¥15 IDEA中圈复杂度如何具体设置
• ¥50 labview采集不了数据
• ¥15 请上面代码做什么处理或什么混淆
• ¥15 英雄联盟自定义房间置顶
• ¥15 W5500网线插上无反应
• ¥15 如何用字典的Key，显示在WPF的xaml中
• ¥15 weautomate读取Excel表格信息然后填写到网页一直报错，如何解决？
• ¥15 C#如何在Webview2中获取网页验证码