python-3.x - 仿真中的命令行参数
问题描述
我正在尝试输入命令行参数以从命令行设置 a 和 r 的值。我对python真的很陌生,所以任何帮助都将不胜感激。a = 1/(# 感染天数) r = 疾病的传染性
import matplotlib.pyplot as plt
import numpy as np
import sys
population = 763
Scur = population -1 # number of people susceptible
Icur = 1 # number of people infected
Rcur = 0 # number of people recovered
trans_const = 0.00218 # infectiousness of disease r = kb/N
recov_rate = 0.5 # recovery rate a = 1/(# days infected)
simlength = 20 # number of days in simulation
SIRarray = np.zeros((simlength+1,3)) # using floats as ~% of popn
SIRarray[0,:] = Scur, Icur, Rcur # record initial values
for i in range(1, simlength+1):
new_infected = trans_const * Scur * Icur # = rSI
new_recovered = recov_rate * Icur # = aI
Scur = Scur - new_infected
Icur = Icur + new_infected - new_recovered
Rcur = Rcur + new_recovered
SIRarray[i,:] = Scur, Icur, Rcur
print("SIR Model Simulation")
print("Scur\t\tIcur\t\tRcur")
print("----------------------------------------")
for i in range(len(SIRarray)):
print("{0:.2f}\t\t{1:.2f}\t\t {2:.2f}".format(SIRarray[i,0],
SIRarray[i,1], SIRarray[i,2]))
a = int(sys.argv[1])
r = int(sys.argv[1])
plt.plot(SIRarray[:,0], "b")
plt.plot(SIRarray[:,1], "r")
plt.plot(SIRarray[:,2], "g" )
plt.title("SIR model parameters r = " + str(trans_const) + " a = " + str(recov_rate))
plt.xlabel("Number of People")
plt.ylabel("Number of People")
plt.legend(['Susceptible People', 'Infected', 'Recovered', 'y = 4x'],
loc='upper left')
plt.legend(['Susceptible People', 'Infected', 'Recovered', 'y = 4x'],
loc='upper left')
plt.savefig('SIR Model Simulation')
plt.show()
解决方案
推荐阅读
- javascript - Json数组到Javascript中的json
- c++ - 使用 Android NDK 在 constexpr 构造函数(c++17)中分配给 const char * 失败
- swagger - 为不同的 API 组生成多个 swagger JSON 文件
- echarts - 禁用 echarts 树形图单个节点上的点击事件
- python - 如何将视觉效果导入为 vs?
- javascript - 选择第二个单选按钮时未选中第一个单选按钮
- c# - 如何检查存储在 asp.net 缓存中的令牌
- python - 如何安装pyaudio?pip 安装 pyaudio,报错
- anylogic - 如何在模拟过程中获取当前时间
- html - 周视图显示多天而不是几小时