Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Lab 4

1383 views
ubuntu2004
Kernel: SageMath 9.4
#Lab 4
#1 r=2.5 #r value of 2.5 iteration=[0.5] #list with initial value f(x)=r*x*(1-x) #function that will be iterated for i in srange(0,20): #creates a loop to iterate 20 times iteration.append(f(iteration[i])) #solve equation for initial value and add to list show(list_plot(iteration, plotjoined=True)) #plot iteration values #equilibrium behavior
Image in a Jupyter notebook
r=3.1 #r value of 3.1 iteration=[0.5] #list with initial value f(x)=r*x*(1-x) #function that will be iterated for i in srange(0,20): #creates a loop to iterate 20 times iteration.append(f(iteration[i])) #solve equation for initial value show(list_plot(iteration, plotjoined=True)) #plot iteration values #oscillation points; period = 2
Image in a Jupyter notebook
r=3.5 #r value of 3.5 iteration=[0.5] #list with initial value f(x)=r*x*(1-x) #function that will be iterated for i in srange(0,20): #creates a loop to iterate 20 times iteration.append(f(iteration[i])) #solve equation for initial value show(list_plot(iteration, plotjoined=True)) #plot iteration values #period-doubling oscillation; period = 4
Image in a Jupyter notebook
r=3.9 #r value of 3.9 iteration=[0.5] #list with initial value f(x)=r*x*(1-x) #function that will be iterated for i in srange(0,20): #creates a loop to iterate 20 times iteration.append(f(iteration[i])) #solve equation for initial value show(list_plot(iteration, plotjoined=True)) #plot iteration values #displays chaotic behavior
Image in a Jupyter notebook
#2 rlist=[2.5, 3.1, 3.5, 3.9] #the list of r values for rvalue in rlist: iteration=[0.5] #list with initial value f(x)=rvalue*x*(1-x) #function that will be iterated for i in srange(0,20): #iterate 20 times iteration.append(f(iteration[i])) #solve equation for initial value and add to list show(list_plot(iteration, plotjoined=True)) #plot graph for each r value #when r = 2.5, graph shows equilibrium behavior #when r = 3.1, graph shows oscillatory behavior #when r = 3.5, graph shows oscillatory behavior #when r = 3.9, graph shows chaotic behavior
Image in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebook
#3 #Plot the time series. (You’ll probably want to use the option plotjoined=True). Then, do the same thing using 0.401 for the initial state. Overlay the plots and observe the relationship between the time series. r=3.9 iteration=[0.4] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration.append(f(iteration[i])) graph1=list_plot(list(zip(t,iteration)), plotjoined=True, color = "pink", axes_labels=["time","f(x)"]) show(graph1)
Image in a Jupyter notebook
r=3.9 iteration2=[0.401] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration2.append(f(iteration2[i])) graph2=list_plot(list(zip(t,iteration2)), plotjoined=True, axes_labels=["time","f(x)"], color="purple") show(graph2)
Image in a Jupyter notebook
show(graph1+graph2) #The two graphs have similar values at the beginning (as shown with the overlappinbg graphs) but as time increases, the values start to diverge more and more due to their different initial conditions.
Image in a Jupyter notebook
#4 r=3.8 iteration3=[0.402] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration3.append(f(iteration3[i])) graph3=list_plot(list(zip(t,iteration3)), plotjoined=True, axes_labels=["time","f(x)"], color="green") r=3.8 iteration4=[0.403] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration4.append(f(iteration4[i])) graph4=list_plot(list(zip(t,iteration4)), plotjoined=True, axes_labels=["time","f(x)"], color="lightblue") show(graph3 + graph4)
Image in a Jupyter notebook
r=3.9 iteration5=[0.450] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration5.append(f(iteration5[i])) graph5=list_plot(list(zip(t,iteration5)), plotjoined=True, axes_labels=["time","f(x)"], color="purple") r=3.9 iteration6=[0.461] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration6.append(f(iteration6[i])) graph6=list_plot(list(zip(t,iteration6)), plotjoined=True, axes_labels=["time","f(x)"], color="orange") show(graph5+graph6)
Image in a Jupyter notebook
r=3.95 iteration7=[0.408] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration7.append(f(iteration7[i])) graph7=list_plot(list(zip(t,iteration7)), plotjoined=True, axes_labels=["time","f(x)"], color="green") r=3.95 iteration8=[0.41] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration8.append(f(iteration8[i])) graph8=list_plot(list(zip(t,iteration8)), plotjoined=True, axes_labels=["time","f(x)"], color="brown") show(graph7 + graph8)
Image in a Jupyter notebook
#Near the beginning of the time series, the graphs look similar (have overlap), but after a period of time, the trajectories begin to diverge due to the differences in the initial conditions and r values.
#5 newlist=[] for i in srange(0,8): newlist.append(abs(iteration[i]-iteration2[i])) list_plot(newlist, plotjoined=true)
Image in a Jupyter notebook
#The difference between the first 8 pairs increases before taking a sharp decline, and then it increases again
#6 r=3.9 iteration=[0.4] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration.append(f(iteration[i])) input=[] output=[] for n in srange(len(iteration)-1): #for each value of the length of iteration minus 1 input.append(iteration[n]) output.append(iteration[n+1]) change=list_plot(list(zip(input,output)), axes_labels=["X(t)", "X(tnext)"]) show(change) #The graph represents a Poincare plot (chaos), which is a parabola.
Image in a Jupyter notebook
#7 x>0 x<1 f(x) = 3.9*x*(1-x) r=3.9 iteration=[0.4] f(x)=r*x*(1-x) t = srange(0,20,0.1) for i in srange(0,20): iteration.append(f(iteration[i])) input=[] output=[] for n in srange(len(iteration)-1): #for each value of the length of iteration minus 1 input.append(iteration[n]) output.append(iteration[n+1]) change=list_plot(list(zip(input,output)), axes_labels=["X(t)", "X(tnext)"]) + plot((g(x)), xmin = 0, xmax = 1, color = "pink") show(change) #the graphs correspond with each other. The first graph, the Poincare plot, matches up exactly with the points on the plot of the second equation (3.9x(1-x)). They are the same plot between x = 0 and x = 1; the second equation "fills in" the missing points between the points on the first plot
Image in a Jupyter notebook
#8 r=3.5 result=[0.4] f(x)=r*x*(1-x) for i in srange(0,250): result.append(f(result[i])) result
[0.400000000000000, 0.840000000000000, 0.470400000000000, 0.871933440000000, 0.390829306734183, 0.833286159061513, 0.486221176623084, 0.874335504092217, 0.384555256316090, 0.828353789045148, 0.497643262268932, 0.874980560255434, 0.382863528006822, 0.826976664251470, 0.500801913622436, 0.874997749270897, 0.382818408146164, 0.826939660857104, 0.500886603555247, 0.874997248769475, 0.382819721953635, 0.826940738529418, 0.500884137214436, 0.874997264054851, 0.382819681829817, 0.826940705617371, 0.500884212536454, 0.874997263588666, 0.382819683053543, 0.826940706621148, 0.500884210239226, 0.874997263602885, 0.382819683016219, 0.826940706590532, 0.500884210309292, 0.874997263602451, 0.382819683017358, 0.826940706591466, 0.500884210307155, 0.874997263602465, 0.382819683017323, 0.826940706591438, 0.500884210307220, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218]
newlist = [] newlist.append(result[101:]) print(newlist)
[[0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218, 0.874997263602464, 0.382819683017324, 0.826940706591439, 0.500884210307218]]
#9 #We threw away the first 100 values because it allows us to see the long-term behavior of the graph, not the short term
#10 r = 3.5 f(x) = r*x*(1-x) result = [] result.append(250*[f(x)]) figureone = [] for r in srange(2, 4, 0.01): f(x) = r*x*(1-x) result = [0.4] for i in srange(0, 250): result.append(f(result[i])) if i>100: figureone.append((r, result[i])) forfigureone = list_plot(figureone, size = 1, color = "pink") show(forfigureone)
Image in a Jupyter notebook
#11 #The plot produces chaotic behavior when r is greater than 3.5, so approximately 3.6
#This plot tells us that the behavior of the discrete logistic model becomes increasingly more chaotic as r increases. It begins to double as it becomes more chaotic. This is the opposite from #1 because in that problem, the graph become more neutral as r increased