CoCalc Public FilesLab 7 / lab7-turnin.ipynbOpen with one click!
Author: Ellen Ulitsky
Views : 54
In [1]:
# Lab 7: # Name: Ellen Ulitsky # I worked on this code with:Irene U.,Alex B., and Rachel L. # 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.
In [2]:
#Exercises 32-42
In [1]:
#32 A=matrix([[3,4,5,6],[4,7,8,9]]) type(A)
<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
In [2]:
#33 BlackBear=matrix(RDF,[[.57,.5025],[.33,.917]]) e_vec1=vector([-.8815,.4721]) e_vec2=vector([-.6320,-.7749]) plot(e_vec1,color="red")+plot(e_vec2,color="green")
In [15]:
#34 BlackBear=matrix(RDF,[[.57,.5025],[.33,.917]]) e_vec1=vector([-.8815,.4721]) e_vec2=vector([-.6320,-.7749]) BlackBear1=BlackBear*e_vec1 BlackBear2=BlackBear*e_vec2 plot(e_vec1,color="red")+plot(e_vec2,color="green")+plot(BlackBear1,color="pink")+plot(BlackBear2)
In [ ]:
##e_vec1 is shorter when multiplied by blackbear and e_vec2 is longer when multiplied by blackbear
In [16]:
#35 a=e_vec1.norm() b=e_vec2.norm() c=BlackBear1.norm() d=BlackBear2.norm() c/a
0.30086746117747065
In [17]:
d/b
1.186134283607642
In [18]:
#36 BlackBear.eigenvalues()
[0.3008632979519208, 1.186136702048079]
In [ ]:
#they are equivilent
In [ ]:
#37 # 1. 35,315 larvae/month # 2. .949 # 3. .00003 # 4. .777
In [21]:
#38 m=matrix(RDF,[[0,0,35315],[.00003,.777,0],[0,.071,.949]]) show(m)
(0.00.035315.03×10050.7770.00.00.0710.949)\left(\begin{array}{rrr} 0.0 & 0.0 & 35315.0 \\ 3 \times 10^{-05} & 0.777 & 0.0 \\ 0.0 & 0.071 & 0.949 \end{array}\right)
In [26]:
#39 print ("Dominant eigenvalue- ") max(m.eigenvalues())
Dominant eigenvalue-
1.1344782568718599
In [29]:
print ("Dominant eigenvector- ") m.eigenvectors_right()[2][1]
Dominant eigenvector-
[(0.9999999959626241, 8.392118765878536e-05, 3.212454346004658e-05)]
In [41]:
#40 m=matrix(RDF,[[0,0,35315],[.00003,.777,0],[0,.071,.949]]) v1=vector([1,2,3]) for i in srange(1,500): vec=m*v1 v1/sum(vec)
(9.438455055127952e-06, 1.8876910110255903e-05, 2.8315365165383855e-05)
In [43]:
m=matrix(RDF,[[0,0,35315],[.00003,.777,0],[0,.071,.949]]) v2=vector([3,6,9]) for i in srange(1,500): vec2=m*v2 v2/sum(vec2)
(9.438455055127952e-06, 1.8876910110255903e-05, 2.8315365165383855e-05)
In [ ]:
#The initial conditions are still the same even with different intitial conditions. This means that in the long run, they go to the same equilibrium.
In [ ]:
#41 #in order to be constant, the eigenvalue must be 1. To increase the eigenvalue must be greater then 1. To decrease the eigen value, it has to be below 1.
In [4]:
#42 m=matrix(RDF,[[0,0,35315],[.00003,.777,0],[0,.071,.949]]) p=m.eigenvalues()[2] print ("original model: ") p
original model:
1.1344782568718599
In [8]:
#1: make the adult survival smaller m1=matrix(RDF,[[0,0,35315],[.00003,.777,0],[0,.071,.949*.8]]) f=m1.eigenvalues()[2] print ("reducing adult survival: ") f
reducing adult survival:
1.037508165878595
In [10]:
#2: make the juvinile survival smaller m2=matrix(RDF,[[0,0,35315],[.00003,.777*.8,0],[0,.071,.949]]) g=m2.eigenvalues()[2] print ("reducing juvinile survival: ") g
reducing juvinile survival:
1.0943816049260202
In [11]:
#3: make the larva to juvinile growth smaller m3=matrix(RDF,[[0,0,35315],[.00003*.8,.777,0],[0,.071,.949]]) k=m3.eigenvalues()[2] print ("reducing larva to juvinile production: ") k
reducing larva to juvinile production:
1.111103698696782
In [ ]:
#making the adult survival smaller creates the biggest reduction in growthrate for a particular change in a given parameter.