"非可订阅"问题 -python ode s

2024-09-29 23:17:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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

有人能帮我吗? 谁来帮帮我!你知道吗


Tags: objectisdefnotk2k1floatc2

热门问题