# SIR program, for studying the relationship of temperature, snowfall and persons on a ski-slope
# First, specify the starting and ending points, stepsize, and total number of observation points
tstart=0
tfin=24
stepsize=.5
length=((tfin-tstart)/stepsize)+1
# Next, specify values of parameters, and initial values of variables
T=10
S=0
P=0
a=3.1
b=0.25
q=tstart
# Set up empty lists for the values we're about to compute
Tvalues=[]
Svalues=[]
Pvalues=[]
qvalues=[]
# The following loop does three things:
# (1) stores the current values of T, S, P and q into the lists created above;
# (2) computes the next values of T, S, P using Euler's method;
# (3) increases q by the stepsize
for i in range(length):
# Store current values
Tvalues.append(T)
Svalues.append(S)
Pvalues.append(P)
qvalues.append(q)
# Compute rates of change using SIR equations
Tprime=a*sin(b*t)+4
#Iprime=a*S*I-b*I
#Rprime=b*I
# Net change equals rate of change times stepsize
DeltaT=Tprime*stepsize
#DeltaI=Iprime*stepsize
#DeltaR=Rprime*stepsize
# New values equal current values plus net change
T=T+DeltaS
#I=I+DeltaI
#R=R+DeltaR
q=q+stepsize
# Next time through the loop, the above new values play the role of current values
# Zip the q values with the S/I/R values into lists of ordered pairs, and create plots of these
Tplot=list_plot(list(zip(qvalues,Tvalues)),marker='o',color='blue')
#Iplot=list_plot(list(zip(qvalues,Ivalues)),marker='o',color='red')
#Rplot=list_plot(list(zip(qvalues,Rvalues)),marker='o',color='green')
# Now plot the computed S,I,R values together on a single graph, with axes labelled appropriately
SIRgraph=Tplot
#+Iplot+Rplot
show(SIRgraph,axes_labels=['$t$ (days)','$S,I,R$ (individuals)'])
|
Traceback (click to the left of this block for traceback)
...
NameError: name 't' is not defined
Traceback (most recent call last): length=((tfin-tstart)/stepsize)+1
File "", line 1, in <module>
File "/tmp/tmpVHz1ob/___code___.py", line 42, in <module>
Tprime=a*sin(b*t)+_sage_const_4
NameError: name 't' is not defined
|