成分:"takes 1 positional argument but 2 were given"



我一直在python中使用odient用于一个项目,它一直工作得很好。我对这个问题做了同样的事情,出于某种原因,它一直说我定义的函数有1个位置参数,但给出了2个,尽管以前做这样的问题是没问题的。下面是我的代码:

def sy(J):
Ntot=J[0]
xb=J[1]
dNtotdt=nn2-nv
dxbdt=(-nv*xb-xb*dNtotdt)/Ntot
return[dNtotdt,dxbdt]
#odeint requires that we set up a vector of times (question asks for 0-10)
t_val=np.linspace(0,10,46) #46 for more accuracy
#we also need to make an initial condition vector
Yo=np.array([Ntoto,xbo])
#use odient function to find the concentrations
ans=odeint(sy,Yo,t_val)
print(ans)

请帮

传递给odeint的导数函数需要预期2个输入(y和t),最直接的解决方案是让你的函数接受多个参数,因为你似乎已经忘记了。

def sy(J,t):

在错误中明确提到了函数"Odient"接受1个位置参数,但你试图输入多于1个参数的例子。

#This function take one Parameter "var"
def foo(var):
return var
#Calling the function with print statement
print(foo(var, var2)) #Trying to give more than 1 argument. But it gives error 

就像你这样处理你的代码。

相关内容

最新更新