# Lab 10 # Name: Brian Clark # 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 var("X,Y,Z") # xprim # Plants due to competition with in it's own population at X*(1-X) and Y, which I assume to be herbivores population, being the carring capacity of the plant population # yprim #Herbivores, due to xprim going into this equation, and Z (carnivores) being a output # zprim #Carnivores due to herbivores being an input of this equation

(X, Y, Z)

#2 a1 = 5 b1 = 3 a2 = 0.1 b2 = 2 d1 = 0.4 d2 = 0.01 xprim = X*(1-X) - (a1*X/(1+b1*X)*Y) yprim = (a1*X/(1+b1*X)*Y) - d1*Y - (a2*Y/(1+b2*Y)*Z) zprim = (a2*Y/(1+b2*Y)*Z) - d2*Z t = srange(0,100,0.1) sol = desolve_odeint([xprim,yprim,zprim], ics = [1,0.5,8], dvars = [X,Y,Z], times = t) list_plot(zip(t,sol[:,0]), color = "lightskyblue", axes_labels = ["time","$Plant Population$"]) + list_plot(zip(t,sol[:,1]), color = "red", axes_labels = ["time","$Herbivore Population$"]) + list_plot(zip(t,sol[:,2]), axes_labels = ["Time","$ Carnivore Population$"]) + list_plot(sol, color = "purple") #all time series and trajectory into a 3D space list_plot(zip(t,sol[:,0]), color = "lightskyblue", axes_labels = ["time","$Plant Population$"], plotjoined= true ) #Time series of Plant Population list_plot(zip(t,sol[:,1]), color = "red", axes_labels = ["time","$Herbivore Population$"], plotjoined=true) #Time series of Herbivore Population list_plot(zip(t,sol[:,2]), axes_labels = ["Time","$ Carnivore Population$"], plotjoined=true) #Time Series of Carnivore population list_plot(sol, color = "purple", axes_labels = ["Plant Population", "Herbivore Population", "Carnivore Population"]) #3D trajectory

3D rendering not yet implemented

3D rendering not yet implemented

#3 t = srange(0,100,0.1) sol2 = desolve_odeint([xprim,yprim,zprim], ics = [3,1.5,10], dvars = [X,Y,Z], times = t) list_plot(zip(t,sol[:,0]), color = "lightskyblue", axes_labels = ["time","$Plant Population$"], legend_label = "Original Initial Condition", plotjoined = true) + list_plot(zip(t,sol2[:,0]), color = "green", legend_label = "Second Initial Conditon", plotjoined = true) #Over laying plant population time series list_plot(zip(t,sol[:,1]), color = "red", axes_labels = ["time","$Herbivore Population$"], legend_label = "Original Initial Condition", plotjoined=true) + list_plot(zip(t,sol2[:,1]), color = "lightpink", legend_label = "Second Initial Condition", plotjoined= true) #Over laying herbivore population time series list_plot(zip(t,sol[:,2]), axes_labels = ["Time","$ Carnivore Population$"], plotjoined=true, legend_label = "Original Initial Condition") + list_plot(zip(t,sol2[:,2]), color = "cyan", legend_label = "Second Initial Condition", plotjoined=true) #Overlaying carnivore population time series list_plot(sol, color = "purple", plotjoined = true) + list_plot(sol2, color = "mediumblue", plotjoined = true)#all time series and trajectory into a 3D space #4 #All plots, initially look the same but drastically look different over time.

3D rendering not yet implemented

#5 @interact def bval(b1=(2,3,.01)): a1 = 5 #setting parameters a2 = 0.1 b2 = 2 d1 = 0.4 d2 = 0.01 xprim = X*(1-X) - (a1*X/(1+b1*X)*Y) #defining the differential equations yprim = (a1*X/(1+b1*X)*Y) - d1*Y - (a2*Y/(1+b2*Y)*Z) zprim = (a2*Y/(1+b2*Y)*Z) - d2*Z t = srange(0,100,0.1) #Creating a time interval sol = desolve_odeint([xprim,yprim,zprim], ics = [1,0.5,8], dvars = [X,Y,Z], times = t) #making a trajectory p = list_plot(zip(t,sol[:,0]), color = "lightskyblue", axes_labels = ["time","$Population$"], plotjoined= true, legend_label = "Plant Population" ) + list_plot(zip(t,sol[:,1]), color = "red", axes_labels = ["time","$Population$"], plotjoined=true, legend_label = "Herbivore Population") + list_plot(zip(t,sol[:,2]), axes_labels = ["Time","$ Population$"], plotjoined=true, legend_label = "Carnivore Population") #overlaying time series p2 = list_plot(sol, plotjoined = true, color = "salmon") #trajectory of populations show(p) #displays time series show(p2) #displays trajectory

Interact: please open in CoCalc

#6 # As b1 increases oscillations appear to be getting longer and have more space from one another.

#7 pa = [.9] r = 2.5 #iteration at r = 2.5 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) list_plot(pa, plotjoined=true) pa = [.9] r = 3.1 #iteration at r = 3.1 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) list_plot(pa, plotjoined=true) pa = [.9] r = 3.5 #iteration at r = 3.5 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) list_plot(pa, plotjoined=true) pa = [.9] r = 3.9 #iteration at r = 3.9 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) list_plot(pa, plotjoined=true) # The plot at r = 3.9 may be chaotic due to oscillations being different from one another and not having a steady pattern.

#8 pa = [.4] #initial condition at .4 r = 3.9 #iteration at r = 3.9 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) pa2 = [.401] #initial condition at .401 r = 3.9 #iteration at r = 3.9 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa2[-1] b = f(a) pa2.append(b) list_plot(pa, plotjoined=true, color = "salmon") + list_plot(pa2, plotjoined = true, color = "lightskyblue") #overlays the time series of the iterations at intial conditions x = .4 and x = .401, both time series have simialr oscillations intially, but detour from one another over time.

#9 #first pair pa = [.5] #initial condition at .5 r = 4 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) pa2 = [.6] #initial condition at .6 r = 4 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa2[-1] b = f(a) pa2.append(b) list_plot(pa, plotjoined=true, color = "salmon") + list_plot(pa2, plotjoined = true, color = "lightskyblue")

#second pair pa = [.01] #initial condition at .3 r = 4 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) pa2 = [.310] #initial condition at .301 r = 4 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa2[-1] b = f(a) pa2.append(b) list_plot(pa, plotjoined=true, color = "salmon") + list_plot(pa2, plotjoined = true, color = "lightskyblue")

#third pair pa = [.8] #initial condition at .800 r = 4.0 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) pa2 = [.850] #initial condition at .850 r = 4.0 #iteration at r = 4 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa2[-1] b = f(a) pa2.append(b) list_plot(pa, plotjoined=true, color = "salmon") + list_plot(pa2, plotjoined = true, color = "lightskyblue") # the relationship between the pairs is that the they both may have similar oscillations at the beggining, but then drastically change over time.

#10 pa = [.4] #initial condition at .4 r = 3.9 #iteration at r = 3.9 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa[-1] b = f(a) pa.append(b) pa2 = [.401] #initial condition at .401 r = 3.9 #iteration at r = 3.9 f(X) = r*X*(1-X) for i in srange(0,21,1): a = pa2[-1] b = f(a) pa2.append(b) pa3 = [] for i in srange(0,9,1): pa3.append(abs(pa[i] - pa2[i])) list_plot(pa3, plotjoined=true) #The plot first starts off with small oscillations and then irratically jumps off, probably due to a similar relationship with the time series as they first start off similar but then differ in the long run.