SharedLab 10 / Lab 10-turnin.sagewsOpen in CoCalc
Author: Flora Abgaryan
Views : 22
# Lab 9

# Name:
# I worked on this code with:

# Please do all of your work for this week's lab in this worksheet. If
# you wish to create other worksheets for scratch work, you can, but
# this is the one that will be graded. You do not need to do anything
# to turn in your lab. It will be collected by your TA at the beginning
# of (or right before) next week’s lab.

# Be sure to clearly label which question you are answering as you go and to

#1
#The variable X represents plants because of the change equation which obtains the logistic growth and a herbivore-plant interaction that is causing the amount of X to decrease. The variable Y represents herbivores.
#The change equation displays a growth rate which is proportional to the amount of plants available to the herbivores as food, herbivore death rate,and a term for the interaction which occurs between herbivore-carnivore. This thereby shows how the amount of herbivores will continue to decrease because of its predators.

#Z represents carnivores as it is modeling a growth rate proportional to the amount of herbivores which are preyed on.

#2
var("X, Y, Z")
t=srange(0,500,0.1)
sol=desolve_odeint([X*(1-X)-(5*X/(1+3*X))*Y, ((5*X/(1+3*X))*Y-0.4*Y-(0.1*Y/(1+2*Y))*Z), ((0.1*Y/(1+2*Y))*Z-0.01*Z)], ics=[1,0.5,8], dvars=[X,Y,Z], times=t)
list_plot(zip(t,sol[:,0]), axes_labels=["time", "X,Y,Z"], color="pink", plotjoined=True, legend_label=["X:plants"])+list_plot(zip(t,sol[:,1]), color="blue", plotjoined=True, legend_label=["Y:herbivores"])+list_plot(zip(t,sol[:,2]), color="magenta", plotjoined=True, legend_label=["Z:carnivores"])

(X, Y, Z)
#3
var("X, Y, Z")
t=srange(0,500,0.1)
sol=desolve_odeint([X*(1-X)-(5*X/(1+3*X))*Y, ((5*X/(1+3*X))*Y-0.4*Y-(0.1*Y/(1+2*Y))*Z), ((0.1*Y/(1+2*Y))*Z-0.01*Z)], ics=[1,0.7,9], dvars=[X,Y,Z], times=t) #simulates differential equations
list_plot(zip(t,sol[:,0]), axes_labels=["time", "X,Y,Z"], color="purple", plotjoined=True, legend_label=["X:plants"])+list_plot(zip(t,sol[:,1]), color="pink", plotjoined=True, legend_label=["Y:herbivores"])+list_plot(zip(t,sol[:,2]), color="pink", plotjoined=True, legend_label=["Z:carnivores"])

(X, Y, Z)
list_plot(sol, color="blue", xmin=0, xmax=50, ymin=0, ymax=50, plotjoined=True)

3D rendering not yet implemented
#4
#The plot with the light pink illustrates a drastic difference in comparison to the other two plots. These bottom two plots illustrate an oscillatroy behavior; however, the light pink one illustrates a more chaotic one witch general patterns.

#5
@interact
def chaos_change(b1=(2,3)):
var("X", "Y", "Z")
a1 =5
a2=.1
b2= 2
d1=.4
d2=.01
t= srange(0,500,0.1)
sol= desolve_odeint([X*(1-X) - ((a1*X)/(1+b1*X))*Y, ((a1*X)/(1+b1*X))*Y - (d1*Y) - ((a2*Y)/(1+ b2*Y))*Z, ((a2*Y)/(1+ b2*Y))*Z - d2*Z ],  ics = [1,.5,8], dvars=[X,Y,Z], times= t)
p= list_plot(zip(t,sol[:,0]), plotjoined=True, color="black", legend_label=["X:plants"])+list_plot(zip(t,sol[:,1]), plotjoined=True, color="yellow", legend_label=["Y:herbivores"])+list_plot(zip(t,sol[:,2]), plotjoined=True, color="purple", legend_label=["Z:carnivores"])
show (p)

#6
#As you increase b1, the model becomes more chaotic. We observe a general pattern as well.

#7
chaos=[0.7]
iterate=srange(0,20,1)
for i in iterate:
log=2.5*chaos[i]*(1-chaos[i]) #r=2.5
chaos.append(log)
chaos
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"])

[0.700000000000000, 0.525000000000000, 0.623437500000000, 0.586907958984375, 0.606117516662925, 0.596847681643234, 0.601551316400827, 0.599218325343148, 0.600389309790253, 0.599804966199591, 0.600097421804746, 0.599951265370107, 0.600024361377286, 0.599987817827665, 0.600006090715154, 0.599996954549681, 0.600001522701973, 0.599999238643217, 0.600000380676942, 0.599999809661167, 0.600000095169326]
chaos=[0.7]
iterate=srange(0,20,1)
for i in iterate:
log=3.1*chaos[i]*(1-chaos[i]) #r=3.1
chaos.append(log)
chaos
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"])

[0.700000000000000, 0.651000000000000, 0.704316900000000, 0.645589273560609, 0.709291666614692, 0.639210694685499, 0.714923185704061, 0.631804875165135, 0.721145172136380, 0.623393919806390, 0.727799215719924, 0.614133303683901, 0.734618125869615, 0.604358438541631, 0.741238880545973, 0.594591787790070, 0.747262420416303, 0.585470015894601, 0.752354116787227, 0.577583939195669, 0.756340270374537]
chaos=[0.7]
iterate=srange(0,20,1)
for i in iterate:
log=3.5*chaos[i]*(1-chaos[i]) #r=3.5
chaos.append(log)
chaos
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"])
#this plot is chaotic

[0.700000000000000, 0.735000000000000, 0.681712500000000, 0.759431985703125, 0.639432656779467, 0.806954869781968, 0.545225477709974, 0.867841296580666, 0.401424731854490, 0.840990207785143, 0.468039873681258, 0.871424926139915, 0.392152334846855, 0.834291083923553, 0.483873149232256, 0.874089736395102, 0.385199041933450, 0.828872590094508, 0.496449868195855, 0.874955887974606, 0.382928287256111]
chaos=[0.7]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i]) #r=3.9
chaos.append(log)
chaos
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"])

[0.700000000000000, 0.819000000000000, 0.578132100000000, 0.951191962303401, 0.181060671295945, 0.578283047962645, 0.951099881166545, 0.181384699124963, 0.579088731188408, 0.950605393136130, 0.183123640738870, 0.583398554471505, 0.947874256337047, 0.192693736991093, 0.606695156790452, 0.930602959718097, 0.251866255219857, 0.734875614335394, 0.759850438583228, 0.711663223315605, 0.800274851593028]

#8
chaos=[0.4]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i]) #r=3.9
chaos.append(log)
chaos
chaos2=[0.401]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos2[i]*(1-chaos2[i]) #r=3.9
chaos2.append(log)
chaos2
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"], color="pink", legend_label=["chaos.inital=0.4"])+list_plot(chaos2, plotjoined=True, color="yellow", legend_label=["chaos.inital=0.401"]) #overlays both plots

[0.400000000000000, 0.936000000000000, 0.233625600000000, 0.698274248196096, 0.821680557758864, 0.571434313163791, 0.955098841720988, 0.167251672630438, 0.543186347467759, 0.967726263630336, 0.121805355010580, 0.417178360955173, 0.948248246813120, 0.191386685992959, 0.603555507428607, 0.933177401836695, 0.243193620298242, 0.717796885043458, 0.790001615774931, 0.647006345106925, 0.890717624543385] [0.401000000000000, 0.936776100000000, 0.230983890028281, 0.692758297045167, 0.830092531788963, 0.550051789782894, 0.965229791524163, 0.130888840205697, 0.443652111689687, 0.962617170383577, 0.140342879298539, 0.470522346562066, 0.971611164996393, 0.107573345297906, 0.374405150649361, 0.913481141884702, 0.308230046692319, 0.831574711532643, 0.546227021620975, 0.966665943641010, 0.125669298478017]
#Observe a similiar general pattern for both plots. Follows but never repeats exactly.

#9
chaos=[0.3]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i]) #r=3.8
chaos.append(log)
chaos
chaos2=[0.599]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos2[i]*(1-chaos2[i]) #r=3.8
chaos2.append(log)
chaos2
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"], color="green", legend_label=["chaos.inital=0.3"])+list_plot(chaos2, plotjoined=True, color="indigo", legend_label=["chaos.inital=0.603"])

[0.300000000000000, 0.819000000000000, 0.578132100000000, 0.951191962303401, 0.181060671295945, 0.578283047962646, 0.951099881166544, 0.181384699124966, 0.579088731188415, 0.950605393136126, 0.183123640738886, 0.583398554471542, 0.947874256337023, 0.192693736991178, 0.606695156790656, 0.930602959717928, 0.251866255220426, 0.734875614336495, 0.759850438581212, 0.711663223319692, 0.800274851586280] [0.599000000000000, 0.936776100000000, 0.230983890028281, 0.692758297045167, 0.830092531788964, 0.550051789782891, 0.965229791524164, 0.130888840205693, 0.443652111689675, 0.962617170383572, 0.140342879298560, 0.470522346562124, 0.971611164996406, 0.107573345297857, 0.374405150649211, 0.913481141884555, 0.308230046692793, 0.831574711533351, 0.546227021619143, 0.966665943641671, 0.125669298475614]
chaos=[0.7]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i]) #r=3.9
chaos.append(log)
chaos
chaos2=[0.457]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos2[i]*(1-chaos2[i]) #r=3.9
chaos2.append(log)
chaos2
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"], color="green", legend_label=["chaos.inital=0.7"])+list_plot(chaos2, plotjoined=True, color="indigo", legend_label=["chaos.inital=0.457"])

[0.700000000000000, 0.819000000000000, 0.578132100000000, 0.951191962303401, 0.181060671295945, 0.578283047962645, 0.951099881166545, 0.181384699124963, 0.579088731188408, 0.950605393136130, 0.183123640738870, 0.583398554471505, 0.947874256337047, 0.192693736991093, 0.606695156790452, 0.930602959718097, 0.251866255219857, 0.734875614335394, 0.759850438583228, 0.711663223315605, 0.800274851593028] [0.457000000000000, 0.967788900000000, 0.121576825643482, 0.416504014328751, 0.947810839469467, 0.192915263009238, 0.607225960798528, 0.930160113990247, 0.253352877694400, 0.737744268527630, 0.754562884850823, 0.722271176860063, 0.782322543355245, 0.664146527902360, 0.869918077772639, 0.441326401374283, 0.961573894414802, 0.144103205979537, 0.481016140823230, 0.973594491053950, 0.100262206369064]

chaos=[0.9]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i]) #r=3.9
chaos.append(log)
chaos
chaos2=[0.788]
iterate=srange(0,20,1)
for i in iterate:
log=3.9*chaos2[i]*(1-chaos2[i]) #r=3.9
chaos2.append(log)
chaos2
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"], color="pink", legend_label=["chaos.inital=0.9"])+list_plot(chaos2, plotjoined=True, color="indigo", legend_label=["chaos.inital=0.788"])

[0.900000000000000, 0.351000000000000, 0.888416100000000, 0.386618439717082, 0.924864024972463, 0.271013185108374, 0.770503650562574, 0.689628322626052, 0.834760287106317, 0.537948645688336, 0.969383611132642, 0.115748199840313, 0.399167160888757, 0.935347680371388, 0.235842349061481, 0.702860868257511, 0.814505125706254, 0.589237451027523, 0.943943041603031, 0.206366845667775, 0.638740325639939] [0.788000000000000, 0.651518400000000, 0.885464480399616, 0.395526823965990, 0.932432886408531, 0.245707015134309, 0.722806803607580, 0.781392800238075, 0.666190558699281, 0.867284722976961, 0.448897535844175, 0.964815298813090, 0.132392278158262, 0.447971795085077, 0.964442956983990, 0.133741684861074, 0.451833901707221, 0.965952105203476, 0.128265679060149, 0.436073019078014, 0.959062030329780]


# 10
chaos=[0.4] #initial condition
iterate=srange(0,8,1) #iterates 8 times
for i in iterate:
log=3.9*chaos[i]*(1-chaos[i])
chaos.append(log)
chaos
chaos2=[0.401]
iterate=srange(0,8,1) #iterates 8 times
for i in iterate:
log=3.9*chaos2[i]*(1-chaos2[i])
chaos2.append(log)
chaos2
list_plot(chaos, plotjoined=True, axes_labels=["time", "x"], color="pink", legend_label=["chaos.inital=0.4"])+list_plot(chaos2, plotjoined=True, color="green", legend_label=["chaos.inital=0.401"])

[0.400000000000000, 0.936000000000000, 0.233625600000000, 0.698274248196096, 0.821680557758864, 0.571434313163791, 0.955098841720988, 0.167251672630438, 0.543186347467759] [0.401000000000000, 0.936776100000000, 0.230983890028281, 0.692758297045167, 0.830092531788963, 0.550051789782894, 0.965229791524163, 0.130888840205697, 0.443652111689687]
#I observe that the initial growth begins at almost exactly the same rate which is seen in chaotic behavior but because the model is very sensitive to the change in parameters, we observe that a difference between the two exists. We cannot also say the long-term behavior along chaotic models.