# Name: Alejandro Gutierrez
# I worked on this code with: Sandra Foxx, Alette Eide, Molly Croissette
# 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.
#Exercise 33
bbmatrix=[[0.57,0.5025],[0.33,0.917]]
M=matrix(RDF,bbmatrix)
show(M.eigenvectors_right())
EV1= plot(M.eigenvectors_right()[0][1][0] , color="lime")
EV2= plot(M.eigenvectors_right()[1][1][0], color="dodgerblue")
EV1+EV2
#Exercise 34
EV1= plot(M.eigenvectors_right()[0][1][0] , color="lime")
EV2= plot(M.eigenvectors_right()[1][1][0], color="dodgerblue")
EV3 = plot(M*(M.eigenvectors_right()[0][1][0]), color = "fuchsia")
EV4 = plot(M*(M.eigenvectors_right()[1][1][0]), color = "khaki")
show(EV1+EV2+EV3+EV4)
#The eigenvector of bbmatrix*EV1 is shorter than the EV1 vector alone because its eigenvalue is less than 1
#The eigenvector for bbmatrix*EV2 is longer than EV2 vector alone because its eigenvalue is larger than 1.
#Exercise 35
v1=M.eigenvectors_right()[0][1][0]
v2= M.eigenvectors_right()[1][1][0]
OG1=M*v1
OG2=M*v2
show(OG1.norm()/v1.norm())
show(OG2.norm()/v2.norm())
#Exercise 36
M.eigenvalues()
#Evidently, they are the same.
[0.3008632979519208, 1.186136702048079]
#Exercise 37
#1) 35315 is the average production of larva the adults produce per month
#2) The fraction of adults that survive from one month to the next is 0.949
#3) 0.00003 is the fraction of larvae that survive to become juveniles
#4) The fraction of juveniles in a given month that will remain juveniles in the following month is 0.777
#Exercise 38
L=matrix(RDF,[[0,0,35315],[0.00003,0.777,0],[0,0.071,0.949]])
show(L)
#39
show(["Dominant Eigenvalue"])
show(max(L.eigenvalues()))
show(["Dominant Eigenvector"])
show(L.eigenvectors_right()[2][1]) #shows the longterm proportion
#40
LM= matrix([[0,0,35315],[0.00003,0.777,0],[0,0.071,0.949]])
v1=vector([25,15,8])
v2=vector([12,34,50])
L1= [v1[0]/sum(v1)]
J1= [v1[1]/sum(v1)]
A1= [v1[2]/sum(v1)]
L2= [v2[0]/sum(v2)]
J2= [v2[1]/sum(v2)]
A2= [v2[2]/sum(v2)]
for i in srange(0,100,0.1):
v1= LM*v1
L1.append(v1[0]/sum(v1))
J1.append(v1[1]/sum(v1))
A1.append(v1[2]/sum(v1))
v2= LM*v2
L2.append(v2[0]/sum(v2))
J2.append(v2[1]/sum(v2))
A2.append(v2[2]/sum(v2))
show("L1 Prop.:",L1[-1])
show("J1 Prop.:",J2[-1])
show("A1 Prop.:",A1[-1])
show("L2 Prop.:",L2[-1])
show("J2 Prop.:",J2[-1])
show("A2 Prop.:",A2[-1])
#In the long run, the proportions match the largest eigenvalues and it matches the last eigenvector. They are the same as the dominant eigenvector value.
#41
#In order for the population to be constant, the dominant eigenvalue must be equal to one whereas in order for a population to be declining, the dominant eiganvalue must be reduced to a number less than 1.
#42
LFP1= matrix(RDF,[[0,0,25000],[0.00003,0.777,0],[0,0.071,0.949]]) #manipulating the number of larvae produced by adults
LFP2= matrix(RDF,[[0,0,35315],[0.00003,0.777,0],[0,0.071,0.85]]) #manipulating fraction of adult survival rate per month
LFP3= matrix(RDF,[[0,0,35315],[0.00001,0.777,0],[0,0.071,0.5]]) #manipulating the fraction of larvae survival that turn into juveniles
#LFP1
show("LFP1 Dom. Eigenvector:",LFP1.eigenvalues()[2])
show("LFP1:",LFP1.eigenvectors_right())
#LFP2
show("LFP2 Dom. Eigenvector:",LFP2.eigenvalues()[2])
show("LFP2:",LFP2.eigenvectors_right())
#LFP3
show("LFP3 Dom. Eigenvector:",LFP3.eigenvalues()[2])
show("LFP3:",LFP3.eigenvectors_right())
#By decreasing the amount of adults that surive from one month to another, we can see that in each matrix there is a bigger reduction in growth rate.