我制作了此代码,我问是否有人可以帮助我重复该功能,因为我需要使用不同的K2值
我执行了此代码,需要使用不同的K2值,并且仅使用一个函数。无需重复相同的函数3次。由于K2会影响每个图的曲线。
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def F(Y,t):
k2=[3,6,9]
T1=15
p1=15
p2=4
for i in k2:
return np.array([ -p1*Y[1]*Y[0] -p2*Y[2]*Y[0] , p1*Y[1]*Y[0]-Y[1]*(1/T1) , p2*Y[2]*Y[0]-Y[2]*(1/T1)+p2*k2*Y[2]*Y[1]*(1/T1)])
T=np.linspace(0,140,100)
conditions_initiales = [0.8 , 0.01 ,10**-7]
Y=odeint(F,np.array(conditions_initiales),T)
u=Y[:,0]
y2=Y[:,2]
plt.plot(T,y2)
plt.legend(['y2','z2','v2'])
plt.grid()
plt.xlabel('Temps en jours ')
plt.title("La propagation de deux variants ")
plt.show()
这个代码给了我这个错误类型:不能将序列乘以“ numpy.float64”类型
i did this code and i need to use different values of k2 and only use one function .Without repeating the same function 3 times .Because k2 influence the curve of every graph.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def F(Y,t):
k2=[3,6,9]
T1=15
p1=15
p2=4
for i in k2:
return np.array([ -p1*Y[1]*Y[0] -p2*Y[2]*Y[0] , p1*Y[1]*Y[0]-Y[1]*(1/T1) , p2*Y[2]*Y[0]-Y[2]*(1/T1)+p2*k2*Y[2]*Y[1]*(1/T1)])
T=np.linspace(0,140,100)
conditions_initiales = [0.8 , 0.01 ,10**-7]
Y=odeint(F,np.array(conditions_initiales),T)
u=Y[:,0]
y2=Y[:,2]
plt.plot(T,y2)
plt.legend(['y2','z2','v2'])
plt.grid()
plt.xlabel('Temps en jours ')
plt.title("La propagation de deux variants ")
plt.show()
and this code gave me this error TypeError: can't multiply sequence by non-int of type 'numpy.float64'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
odeint()
通过args
参数传递额外参数:You can pass extra arguments through
odeint()
with theargs
parameter: