新人请教个python问题
对python基本是一窍不通。。。
想用它画个微分方程 dy/dt=r*y*(1-y/k) y(0)=0.1, 0.2 ,1.5
的图
执行时报错
TypeError: logistic() takes exactly 3 arguments (2 given)
odepack.error: Error occurred while calling the Python function named logistic
结果画出来的图是3条直线没随时间变化。。
这里该怎么改啊?
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
r=input("input r:")
K=input("input K:")
y001=input("input initial value y001:")
y002=input("input initial value y002:")
y003=input("input initial value y003:")
def logistic(t,r,K):
return r*y*(1-y/K)
t=np.arange(0.,10,0.01)
y1=odeint(logistic, y001, t)
y2=odeint(logistic, y002, t)
y3=odeint(logistic, y003, t)
A1=plt.gca()
A1.set_title('logistic curve r='+repr(r)+' K='+repr(K))
A1.grid()
A1.set_xlabel('t')
A1.set_ylabel('y')
A1.plot(t,y1)
A1.plot(t,y2)
A1.plot(t,y3)
plt.show()
[解决办法]
def logistic(t,r,K): return r*y*(1-y/K)t=np.arange(0.,10,0.01)y1=odeint(logistic, y001, t)y2=odeint(logistic, y002, t)y3=odeint(logistic, y003, t)