数组的大小不匹配

the size of array does not match

我在尝试 运行 我的代码时遇到了这个问题 “func (1) 返回的数组大小与 y0 (2) 的大小不匹配”

import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint

def F(X,t):
    dX_1 = X[0]*(1-X[1]) #proie
    dX_2 = 1.1*X[1]*(X[0]-1) #prédateur

t0 = 0                            # temps initial
tfinal = 20                       # temps final
t = np.linspace(t0, tfinal, 1000) # n=1000
H = [[1.01,1.01], [1,2], [1,3], [1,4], [1,5]] # conditions initiales 

for i in range (len(H)):
    solution=odeint(F, H[i], t)
    x = solution[:,0]
    y = solution[:,1]
    plt.figure(1)
    plt.grid(True)
    plt.suptitle("modèle de Lotka-volterras")
    plt.plot(x,y)
    plt.xlabel('proie')
    plt.ylabel('prédateur')
plt.show()

plt.figure(2)
sol = odeint(F,[1,2],t)
plt.grid(True)
plt.suptitle("modèle de Lotka-volterras")
plt.plot(t,sol[:,0])
plt.plot(t,sol[:,1])
plt.legend(["proie","prédateur"])
plt.xlabel('temps')
plt.ylabel('x(t),y(t)')
plt.show()

我该怎么做才能让它变得更好,在此先感谢

你几乎忘记了从你的函数中返回。现在对我来说它有效。

from scipy.integrate import odeint
def F(X,t):
    dX_1=X[0]*(1-X[1]) #proie
    dX_2=1.1*X[1]*(X[0]-1) #prédateur
    return dX_1,dX_2
t0=0 #temps initial
tfinal=20 #temps final
t=np.linspace(t0,tfinal,1000) #n=1000
H=[[1.01,1.01],[1,2],[1,3],[1,4],[1,5]]#conditions initiales 
for i in range (len(H)):
    solution=odeint(F,H[i],t)
    x=solution[:,0]
    y=solution[:,1]
    plt.figure(1)
    plt.grid(True)
    plt.suptitle("modèle de Lotka-volterras")
    plt.plot(x,y)
    plt.xlabel('proie')
    plt.ylabel('prédateur')
plt.show()
plt.figure(2)
sol=odeint(F,[1,2],t)
plt.grid(True)
plt.suptitle("modèle de Lotka-volterras")
plt.plot(t,sol[:,0])
plt.plot(t,sol[:,1])
plt.legend(["proie","prédateur"])
plt.xlabel('temps')
plt.ylabel('x(t),y(t)')
plt.show()