我正在尝试使用scipy.integrate.solve\u ivp解决方案. 但是发生了“类型错误:”float“object is not subscriptable”
当我使用odeint时,它是有效的。 我只是用相同的设置更改解算器。你知道吗
def f(z, t):
c1 = z[0]
c2 = z[1]
dc1dt = -k1*c1 + k2*c2*(1-c1-c2)
dc2dt = k1*c1 - k2*c2*(1-c1-c2) - 2*k3*c2*c2
dcdt = [dc1dt, dc2dt]
return dcdt
def main():
k1 = 0.04
k2 = 10.0
k3 = 1500.0
z0 = [0.9, 0.1]
sol = solve_ivp(f,[0, 3000] , z0, method = 'RK45')
return sol
main()
TypeError: 'float' object is not subscriptable
有人能帮我吗? 谁来帮帮我!你知道吗
f
中参数的顺序仅对odeint
有效,甚至可以使用选项tfirst=True
避免这种情况。你知道吗错误是因为数组和标量是交换的,所以不能访问标量的组件。你知道吗
相关问题 更多 >
编程相关推荐