我试图将一个数组传递到一个ODE中,然后使用ODEINT函数求解该ODE。但是,我得到了以下错误:RuntimeError: The size of the array returned by func (50) does not match the size of y0 (1)
下面是我的示例代码:from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
#First ODE
def eq1 (x,t):
return (0.5*(x)+2*x**2)
#Second ODE
def eq2 (y,t,m):
p = np.sqrt(y)+m*y**2
return p
t = np.linspace(0,1,50)
IC = [2] # Initial Condition
m = [0.1]*len(t) # A random variable
#Solver for the first ODE
one = odeint(eq1,IC,t)
plt.plot (t,one)
#Solver for the Second ODE
two = odeint (eq2,IC,t,(m,))
plt.plot (t,two)
第一个解算器工作正常,但第二个解算器抛出错误。基于错误消息,我了解到IC的维数与变量m的维数不同。因此,如果我注释掉与第一个ODE的解算器相关的行并将IC更改为IC = [2]*len(m),错误消息就会消失。然而,two.shape是(50,50)。我不知道解的哪个维度(两个)才是真正的答案。在
我真的很感谢你的指导。
谢谢您!在