CoCalc
SharedLab 10 / Lab 10-turnin.sagewsOpen in CoCalc
Authors: Enrique Jimenez, Omeed Zokaeim
Views : 3
# Lab 9 # Name: Omeed Zokaeim # 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 # use enough comments that you and the grader can understand your code.
#1 #x reepresents plants b/c it hasd no aniumal death rate #y represents herbivores #z represents carnivores
#2 #2 var("X,Y,Z") t=srange(0,100) 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], times=t, dvars=[X,Y,Z]) list_plot(sol, plotjoined=True)
(X, Y, Z)
3D rendering not yet implemented
list_plot(zip(t,sol[:,0]), color="blue", plotjoined=True) + list_plot(zip(t, sol[:,1]), color="magenta", plotjoined=True)+ list_plot(zip(t, sol[:,2]), color="pink", plotjoined=True)
#3 var("X,Y,Z") t=srange(0,100) sol2=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=[3,0.3,6], times=t, dvars=[X,Y,Z]) list_plot(sol2, plotjoined=True) + list_plot(sol, plotjoined=True, color="pink")
(X, Y, Z)
3D rendering not yet implemented
list_plot(zip(t,sol[:,0]), color="yellow", plotjoined=True) + list_plot(zip(t, sol[:,1]), color="purple", plotjoined=True)+ list_plot(zip(t, sol[:,2]), color="orange", plotjoined=True)+ list_plot(zip(t,sol2[:,0]), color="blue", plotjoined=True) + list_plot(zip(t, sol2[:,1]), color="magenta", plotjoined=True)+ list_plot(zip(t, sol2[:,2]), color="pink", plotjoined=True)
#4 #The trajectories for the first and second look similar, while the time series looks different. #5 var("b1") @interact def b1_func(b1=(2,3,0.1)): var=("X,Y,Z") t=srange(0,1000, 0.1) sol3=desolve_odeint([(X*(1-X)-((5*X)/(1+b1*X))*Y), (((5*X)/(1+b1*X))*Y-(0.4*Y)-((0.1*Y)/(1+2*Y))*Z),((0.1*Y)/(1+2*Y))*Z-0.01*Z], ics=[3,0.3,6], times=t, dvars=[X,Y,Z]) time_series= list_plot(zip(t, sol3[:,0]), color="green", axes_labels=["Time", "X,Y,Z"], plotjoined=True, legend_label=["X"]) + list_plot(zip(t, sol3[:,1]), color="blue", axes_labels=["Time", "X,Y,Z"], plotjoined=True, legend_label=["Y"]) + list_plot(zip(t, sol3[:,2]), color="green", axes_labels=["Time", "X,Y,Z"], plotjoined=True, legend_label=["Z"]) trajectory=list_plot(sol3, axes_labels=["X,Y,Z"], plotjoined=True, color="blue") show(time_series) show(trajectory)
b1
Interact: please open in CoCalc
#6 #as you increase b1, the function becomes more chaotic on the time series, but the trajectory appears somewhat similar #7 r=2.5 X_N=[0.01] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N[i]*(1-X_N[i]) X_N.append(X_N_1) X_N list_plot(zip(N, X_N), axes_labels=["N", "X_N"], plotjoined=True)
[0.0100000000000000, 0.0247500000000000, 0.0603435937500000, 0.141755611108337, 0.304152394569098, 0.529109288617454, 0.622881623290464, 0.587250266643751, 0.605968477426486, 0.596926704479781, 0.601513034896723, 0.599237759365142, 0.600379667790466, 0.599809805735689, 0.600095006697510, 0.599952474085564, 0.600023757310437, 0.599988119933757, 0.600005939680282, 0.599997030071660, 0.600001484942119]
r=3.1 X_N=[0.01] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N[i]*(1-X_N[i]) X_N.append(X_N_1) X_N list_plot(zip(N, X_N), axes_labels=["N", "X_N"], plotjoined=True)
[0.0100000000000000, 0.0306900000000000, 0.0922191840900000, 0.259515899144902, 0.595718931431336, 0.746597447113494, 0.586488067139033, 0.751811424151918, 0.578432120666407, 0.755930047588087, 0.571949413298834, 0.758952173970456, 0.567125691947521, 0.761031838589756, 0.563773375651600, 0.762392165329800, 0.561566089877971, 0.763249811389127, 0.560168564091127, 0.763777206075157, 0.559306915221071]
r=3.5 X_N=[0.01] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N[i]*(1-X_N[i]) X_N.append(X_N_1) X_N list_plot(zip(N, X_N), axes_labels=["N", "X_N"], plotjoined=True)
[0.0100000000000000, 0.0346500000000000, 0.117072821250000, 0.361783715210979, 0.808136905166921, 0.542680766859531, 0.868624232490988, 0.399406613271505, 0.839583396912720, 0.471390907894264, 0.872135319471099, 0.390303564007500, 0.832883421756902, 0.487160196317958, 0.874422988044923, 0.384325991082290, 0.828168332813169, 0.498069408685187, 0.874986954860113, 0.382846742896588, 0.826962900225217]
r=3.9 X_N=[0.01] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N[i]*(1-X_N[i]) X_N.append(X_N_1) X_N list_plot(zip(N, X_N), axes_labels=["N", "X_N"], plotjoined=True)
[0.0100000000000000, 0.0386100000000000, 0.144765144810000, 0.482851970866745, 0.973853185877696, 0.0993063171108759, 0.348833832721725, 0.885880280494547, 0.394275995589255, 0.931407496076291, 0.249161532083820, 0.729612245752508, 0.769385044741910, 0.691983620910656, 0.831254928277931, 0.547053672717172, 0.966365212346918, 0.126763605979193, 0.431708917295546, 0.956811679289909, 0.161160049690902]
#3.9 might be chaotic because there is no stability whatsoever #8 r=3.9 X_N8=[0.4] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N8[i]) X_N8.append(X_N_1) X_N8 r=3.9 X_N0=[0.401] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N0[i]) X_N0.append(X_N_1) X_N0 list_plot(zip(N, X_N0), plotjoined=True, color="green") + list_plot(zip(N, X_N8), axes_labels=["N", "X_N8, X_N0"], plotjoined=True, color="blue")
[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.934440000000000, 0.239320224000000, 0.693085649395877, 0.835810510971881, 0.526154112598794, 1.05601001692912, -0.208630898945728, 0.788367603821861, 0.448327730314827, 2.08208420273451, -0.514034236815126, 2.46332705324374, -5.41162951973510, 4.78569204982724, -8.91101361579749, 36.0700623486762, -33.2623801639726, 95.9143760479096, -292.431790708660, 740.423698733902]
#9 r=3.7 X_N8=[0.1] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N8[i]) X_N8.append(X_N_1) X_N8 r=4 X_N0=[0.5] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N0[i]) X_N0.append(X_N_1) X_N0 list_plot(zip(N, X_N0), plotjoined=True, color="green") + list_plot(zip(N, X_N8), axes_labels=["N", "X_N8, X_N0"], plotjoined=True, color="blue")
[0.100000000000000, 0.333000000000000, 0.821810700000000, 0.541820131452386, 0.918528983439629, 0.276883913077666, 0.740811083498922, 0.710437081637078, 0.761150068286658, 0.672662374785333, 0.814694506033910, 0.558579261126670, 0.912303339613657, 0.296022037730673, 0.771054066361276, 0.653159864503363, 0.838205606849653, 0.501782779733195, 0.924988240276765, 0.256724483817898, 0.706022985937427] [0.500000000000000, 0.200000000000000, 1.06560000000000, -0.215643127680001, 2.63463967695507, -6.00585568305451, 7.75923494392615, -20.0292646497348, 59.7598776269255, -178.900339473000, 484.048758298383, -1574.14867812878, 3519.38153917530, -12839.3249128987, 15204.0765833608, -46889.5760832088, 122508.169283973, -410744.784692424, 824420.646426627, -3.05031391199104e6, 3.13236208505174e6]
r=3.7 X_N8=[1] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N8[i]) X_N8.append(X_N_1) X_N8 r=4 X_N0=[2] N=srange(0, 20) for i in srange(0, 20): X_N_1=r*X_N8[i]*(1-X_N0[i]) X_N0.append(X_N_1) X_N0 list_plot(zip(N, X_N0), plotjoined=True, color="green") + list_plot(zip(N, X_N8), axes_labels=["N", "X_N8, X_N0"], plotjoined=True, color="blue")
[1, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000] [2, -4, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000]
#when the initial conditions are higher, the graphs are steeper and closer to the y axis #10 f(x)=3.9*x*(1-x) count_val=srange(0, 20) vals1=[0.4] for i in count_val: a=vals1[i] b=f(a) vals1.append(b) vals1 f(x)= 3.9*x*(1-x) vals2=[0.401] for i in count_val: a=vals2[i] b=f(a) vals2.append(b) vals2
[0.400000000000000, 0.936000000000000, 0.233625600000000, 0.698274248196096, 0.821680557758864, 0.571434313163790, 0.955098841720988, 0.167251672630438, 0.543186347467759, 0.967726263630336, 0.121805355010580, 0.417178360955174, 0.948248246813121, 0.191386685992957, 0.603555507428601, 0.933177401836699, 0.243193620298226, 0.717796885043427, 0.790001615774983, 0.647006345106807, 0.890717624543520] [0.401000000000000, 0.936776100000000, 0.230983890028281, 0.692758297045167, 0.830092531788964, 0.550051789782892, 0.965229791524164, 0.130888840205693, 0.443652111689677, 0.962617170383573, 0.140342879298556, 0.470522346562113, 0.971611164996404, 0.107573345297866, 0.374405150649239, 0.913481141884582, 0.308230046692706, 0.831574711533221, 0.546227021619479, 0.966665943641550, 0.125669298476054]
count_val=srange(0,8) vals3=[] for i in count_val: a=abs(vals2[i]-vals1[i]) vals3.append(a) vals3
[0.00100000000000000, 0.000776100000000168, 0.00264170997171956, 0.00551595115092951, 0.00841197403010030, 0.0213825233808989, 0.0101309498031757, 0.0363628324247447]
list_plot(vals3, axes_labels=["Time", "f(x)"], plotjoined=True)
#the graph shows chaotic systems sensitivity, which is based on the initial conditions. The system becomes more chaotic as cvalue of time increases