TypeError: 'int' object is not callable Modeling in python
TypeError: 'int' object is not callable Modeling in python
我在 python 中收到以下错误,我不确定为什么。我正在尝试模拟冰毒如何影响老鼠。
这是我的代码,以及在我的代码中创建的函数:
from scipy import array, linspace
from scipy import integrate
from matplotlib.pyplot import *
def Temp2(z, t, Ta, Te, wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, winhibtomdl, whdtospn, yspn, Tt):
# Dependence of Meth Concentration
# dx
# -- = -x/Ta
# dt
#
# dy
# -- = x/Ta - y/Te
# dt
# x = interperitoneal
# y = blood
# Ta is the time constant of Meth in the absorbtion
# Te is the time constant of Meth in elimination
x = z[0] # Rabbits density
y = z[1] # Sheep density
T = z[2]
D = int(x=1)
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
Pexc = (1+tanhx)*[wexc*yt*yexc]
Pinhib = (1+tanhx)*[winhib*yt*yinhib]
Phd = (1+tanhx)*[whd*yt*yhd]
Pmdl = wexctoinghib*Pexc-winhibtomdl*Pinhib
Pspn = Pmdl + whdtospn*Phd+yspn
V = array([-x/Ta, x/Ta - y/Te, (Pspn-(T-T0))/Tt])
return V
def main():
# set up our initial conditions
IC0 = 1
BC0 = 0
T0 = 37
z0 = array([IC0, BC0, T0])
# Parameters
Ta = 8.25
Te = 57.5
wexc = 1.225
yexc = -0.357
winhib = 1.335
yinhib = 1.463
whd = 0.872
yhd = -3.69
wexctoinhib = 7.47
winhibtomdl = 6.38
whdtospn = 5.66
yspn = -3.35
Tt = 89.2
# choose the time's we'd like to know the approximate solution
t = linspace(0., 1., 60)
# and solve
xode= integrate.odeint(Temp2, z0, t, args=(Ta, Te, wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, winhibtomdl, whdtospn, yspn, Tt))
print (xode)
main()
忽略#s,因为它们与代码所表达的内容无关。这是我收到的错误:
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
类型错误:'int'对象不可调用
我不确定哪里出了问题,我该如何解决?谁能帮帮我?
问题在这里
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
python 中没有隐式乘法,因此当您尝试执行 D(Ta/Te - 1)
时,它被解释为函数调用,而不是 D 乘以括号中的内容。
改写成这样
yt = D*(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
我在 python 中收到以下错误,我不确定为什么。我正在尝试模拟冰毒如何影响老鼠。
这是我的代码,以及在我的代码中创建的函数:
from scipy import array, linspace
from scipy import integrate
from matplotlib.pyplot import *
def Temp2(z, t, Ta, Te, wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, winhibtomdl, whdtospn, yspn, Tt):
# Dependence of Meth Concentration
# dx
# -- = -x/Ta
# dt
#
# dy
# -- = x/Ta - y/Te
# dt
# x = interperitoneal
# y = blood
# Ta is the time constant of Meth in the absorbtion
# Te is the time constant of Meth in elimination
x = z[0] # Rabbits density
y = z[1] # Sheep density
T = z[2]
D = int(x=1)
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
Pexc = (1+tanhx)*[wexc*yt*yexc]
Pinhib = (1+tanhx)*[winhib*yt*yinhib]
Phd = (1+tanhx)*[whd*yt*yhd]
Pmdl = wexctoinghib*Pexc-winhibtomdl*Pinhib
Pspn = Pmdl + whdtospn*Phd+yspn
V = array([-x/Ta, x/Ta - y/Te, (Pspn-(T-T0))/Tt])
return V
def main():
# set up our initial conditions
IC0 = 1
BC0 = 0
T0 = 37
z0 = array([IC0, BC0, T0])
# Parameters
Ta = 8.25
Te = 57.5
wexc = 1.225
yexc = -0.357
winhib = 1.335
yinhib = 1.463
whd = 0.872
yhd = -3.69
wexctoinhib = 7.47
winhibtomdl = 6.38
whdtospn = 5.66
yspn = -3.35
Tt = 89.2
# choose the time's we'd like to know the approximate solution
t = linspace(0., 1., 60)
# and solve
xode= integrate.odeint(Temp2, z0, t, args=(Ta, Te, wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, winhibtomdl, whdtospn, yspn, Tt))
print (xode)
main()
忽略#s,因为它们与代码所表达的内容无关。这是我收到的错误:
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
类型错误:'int'对象不可调用
我不确定哪里出了问题,我该如何解决?谁能帮帮我?
问题在这里
yt = D(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)
python 中没有隐式乘法,因此当您尝试执行 D(Ta/Te - 1)
时,它被解释为函数调用,而不是 D 乘以括号中的内容。
改写成这样
yt = D*(Ta/Te -1)**-1 * (e**-t/Ta - e**-t/Te)