CoCalc Public FilesLab 7 / lab7-turnin.ipynb
Author: Denisse Ramirez
Views : 41
In [1]:
# Lab 7:

# Name:
# 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

In [2]:
#Exercises 32-42

In [1]:
#32
M=matrix([[2,1],[3,6]])
type(M)

<class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
In [8]:
#33
BB = matrix(RDF,[[0.57, 0.5025],[0.33,0.917]])
BB.eigenvectors_right()


[(0.3008632979519208, [(-0.8815235799988788, 0.4721399982059986)], 1), (1.186136702048079, [(-0.6320226312996823, -0.7749499296890257)], 1)]
In [10]:
e_vector1 = vector([-0.8815235799988788, 0.4721399982059986])
e_vector2 = vector([-0.6320226312996823, -0.7749499296890257])
plot(e_vector1, color= "blue")+plot(e_vector2,color="pink")

In [13]:
#34
BB1 = BB*e_vector1
BB2 = BB*e_vector2

plot(e_vector1, color="blue")+ plot(e_vector2, color="pink")+ plot(BB1)+ plot(BB2, color="purple")

#BBq plot above, the first eigenvector was shorter than the original vector when multiplied by the matrix. BB2 eigenvector was longer,

In [19]:
plot(e_vector1, color="blue")+ plot(e_vector2, color="pink")+ plot(0.3008632979519208*e_vector1, color="green")+ plot(1.186136702048079*e_vector2, color="purple")

In [20]:
#35
show("Ratio of new to original e_vector 1 :", BB1.norm()/e_vector1.norm ())
show("Ratio of new to original e_vector 2 :", BB2.norm()/e_vector2.norm ())

$\verb|Ratio|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|new|\phantom{\verb!x!}\verb|to|\phantom{\verb!x!}\verb|original|\phantom{\verb!x!}\verb|e_vector|\phantom{\verb!x!}\verb|1|\phantom{\verb!x!}\verb|:| 0.3008632979519208$
$\verb|Ratio|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|new|\phantom{\verb!x!}\verb|to|\phantom{\verb!x!}\verb|original|\phantom{\verb!x!}\verb|e_vector|\phantom{\verb!x!}\verb|2|\phantom{\verb!x!}\verb|:| 1.186136702048079$
In [21]:
#36
BB.eigenvalues()

[0.3008632979519208, 1.186136702048079]
In [22]:
#37
L = matrix (RDF, [[0,0,35315],[0.00003,0.777,0],[0,0.071,0.949]])
show(L)

$\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 [27]:
#37.1#adults to larvae
35315

In [28]:
#37.2#adults to adults
0.949

In [29]:
#37.3#larvae to juveniles
0.00003

In [ ]:
#37.4#juveniles to juveniles
0.777

In [30]:
#38
L

[ 0.0 0.0 35315.0] [ 3e-05 0.777 0.0] [ 0.0 0.071 0.949]
In [33]:
#39
L = matrix (RDF, [[0,0,35315],[0.00003,0.777,0],[0,0.071,0.949]])
R=L.eigenvectors_right()
R

#Long Term growth rate of lionfish population is thelargets eigenvalue. 1.1344782568718599. Long vector proportions eigenvector dominant eigenvalue (L, J, A)[(0.999999995962624, 8.392118765878533e-05, 3.212454346004658e-05)]


[(0.15026156162015658, [(0.9999999988453299, -4.78668582110772e-05, 4.254893429043022e-06)], 1), (0.44126018150798385, [(-0.9999999959297882, 8.935490586919178e-05, -1.2494978895992127e-05)], 1), (1.1344782568718599, [(0.9999999959626241, 8.392118765878536e-05, 3.212454346004658e-05)], 1)]
In [ ]:


In [25]:
#40
v = vector ([35,10,4])

for i in srange(0,100,1):
v= L*v

Lproportion = v[0]/sum(v)
Jproportion = v[1]/ sum (v)
Aproportion = v[2]/ sum (v)

show("Lproportion1:", Lproportion)
show("Jproportion1:", Jproportion)
show("Aproportion1:", Aproportion)

#This shows that 8.39e-5 are juveniles and 3.21e-5 are adults. Numbers are similar to the values of the dominant eigenvector in previously.

$\verb|Lproportion1:| 0.999883967733462$
$\verb|Jproportion1:| 8.391145043195252 \times 10^{-05}$
$\verb|Aproportion1:| 3.212081610614121 \times 10^{-05}$
In [26]:
#41
#The dominant eigenvalue has to be equal to 1 for it to be constant
#absolute value of the dominant eigenvalue has to be less than 1 for it to be declining.

In [43]:
#42 reduced juvenile
L1=matrix(RDF, [[0,0,35315], [0.00003, 0.777, 0], [0, 0.071, 0.949*0.8]])

show(max(L1.eigenvalues()))

L1=matrix(RDF, [[0,0,35315], [0.00003, 0.777, 0], [0, 0.071, 0.949]])
show(max(L1.eigenvalues()))


$1.037508165878595$
$1.1344782568718599$
In [44]:
#42.2 Reduced juvenile in juvenile equation
L=matrix(RDF, [[0,0,35315], [0.00003, 0.65, 0], [0, 0.071, 0.949]])
R=L.eigenvectors_right()
R

[(0.24917407793237076 + 0.07908515734712433*I, [(-0.9999999972766319, 7.20409435662786e-05 + 1.4214074099761357e-05*I, -7.055757532317094e-06 - 2.2394211278988063e-06*I)], 1), (0.24917407793237076 - 0.07908515734712433*I, [(-0.9999999972766319, 7.20409435662786e-05 - 1.4214074099761357e-05*I, -7.055757532317094e-06 + 2.2394211278988063e-06*I)], 1), (1.1006518441352577, [(0.9999999972985204, 6.65702366680018e-05, 3.116669520492339e-05)], 1)]
In [46]:
#42.3 Reduced juvenile in adult equation
L=matrix(RDF, [[0,0,35315], [0.00003, 0.777, 0], [0, 0.0000000003, 0.949]])
R=L.eigenvectors_right()
R
##Reducing the larvae by reducing the number of adults that become larvae gave the biggest reduction in growth rate

[(4.310369838833594e-10, [(0.9999999992546326, -3.8610038602678676e-05, 1.2205491660763567e-14)], 1), (0.7769999976217786, [(-7.927404687950248e-05, 0.9999999968578128, -1.744186016914439e-09)], 1), (0.9490000019471843, [(0.999999984428012, 0.00017441859996055354, 2.6872433446676137e-05)], 1)]
In [38]:
#44

In [39]:
#45

In [ ]: