Lab7-turnin

pdf

School

University of California, Los Angeles *

*We aren’t endorsed by this school

Course

30B

Subject

Mathematics

Date

Apr 3, 2024

Type

pdf

Pages

11

Uploaded by SargentTree12927

Report
Lab7-turnin January 16, 2024 [1]: # Name: Lauren Reed # I worked on this code with: Room 1 # 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. [2]: #32 m = matrix([ 1 , 7 ]) type (m) [2]: <class 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> [3]: #33 blackbear = [[ 0.57 , 0.5025 ],[ 0.33 , 0.917 ]] M = matrix(RDF,blackbear) M . eigenvectors_right() #output #first number = eigenvalue #coupled number = eigenvector [3]: [(0.3008632979519208, [(-0.8815235799988788, 0.4721399982059986)], 1), (1.186136702048079, [(-0.6320226312996823, -0.7749499296890257)], 1)] [4]: #33 plot eigenvectors (only care about direction for eigenvectors) ev1 = M . eigenvectors_right()[ 0 ][ 1 ][ 0 ] ev2 = M . eigenvectors_right()[ 1 ][ 1 ][ 0 ] 1
[5]: #33 a = plot(ev1, color = "pink" ) b = plot(ev2) a + b [5]: [6]: #34 mv1 = M * ev1 mv2 = M * ev2 [7]: #34 plots c = plot(mv1, color = "green" ) d = plot(mv2, color = "orange" ) c + d [7]: 2
[8]: #34 overlay plots from #33 a + b + c + d [8]: 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
[9]: #35 length of original eigenvectors e = ev1 . norm() show(e) [9]: 1.0 [10]: #35 length of original eigenvectors f = ev2 . norm() show(f) [10]: 0.9999999999999999 [11]: #35 length of eigenvectors from #34 g = mv1 . norm() show(g) [11]: 0.30086329795192085 [12]: #35 length of eigenvectors from #34 h = mv2 . norm() show(h) 4
[12]: 1.186136702048079 [13]: #36 # the first eigenvalue (ev1) of the blackbear matrix model in comparison to its growth rate slightly decreased (0.3008/1.0=0.3008; og eigenvalue=0. 3008632979519208) # the second eigenvalue (ev2) of the blackbear matrix model in comarison to its growth rate slightly increased (1.1861/0.999=1.1872; og eigenvector=1. 186136702048079) #the growth rates and original eigenvalues are basically the same. [14]: #37 #1 How many larvae does the average adult produce each month? # 35,315 #2 What fraction of adults survive from one month to the next? # 0.949 #3 What fraction of larvae survive to become juveniles? # 0.00003 #4 What fraction of juveniles in a given month will still be juveniles in the following month? # 0.777 [2]: #38 matrix for lionfish population L = matrix(RDF, [[ 0 , 0 , 35315 ], [ 0.00003 , 0.777 , 0 ], [ 0 , 0.071 , 0.949 ]]) show(L) [2]: 0.0 0.0 35315.0 3 × 10 −05 0.777 0.0 0.0 0.071 0.949 [3]: #39 Note: dominant eigenvalue tells you the long-term growth rate of the population. dominant eigenvector tells you the long-term age or stage structure of the population. 5
# What is the long-term growth rate of the lionfish population? If the population keeps growing in this way, what will the long-term proportions of larvae, juveniles and adults be? # growth rate of lionfish population growth = matrix(RDF,L) L . eigenvectors_right() [3]: [(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.999999995962624, 8.392118765878533e-05, 3.212454346004658e-05)], 1)] [4]: #39 # the dominant eigenvalue is the number furthest from 0, so it would be the adult population (adult eigenvalue=1.1344782568718599) # per month the adult population would be increasing by 13% # long time proportions for larvae, juveniles, and adults would be found in the dominant eigenvector (determined by eigenvalue), which is 8. 392118765878533e-05 (found in the adult population) [8]: #40 first initial condition = 25 lionfish = vector([ 2 , 3 , 5 ]) for i in srange( 25 ): lionfish = L * lionfish lionfish [8]: (2426715.0952441697, 203.65281366635853, 77.95711485046493) [7]: #40 second initial condition = 50 lionfish2 = vector([ 1 , 7 , 3 ]) for i in srange( 50 ): lionfish2 = L * lionfish2 lionfish2 [7]: (44622225.886445545, 3744.750207488059, 1433.4686405605867) [20]: #41 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
# The population will decline or stay constant if the dominant eigenvalue is equal or less than the absolute value of 1. [2]: #42 #amount of adults that give birth to larvae each month changed from 35315 to 25760 reduce = matrix(RDF, [[ 0 , 0 , 25760 ],[ 0.00003 , 0.777 , 0 ], [ 0 , 0.071 , 0.949 ]]) reduce . eigenvectors_right() [2]: [(0.09394559374969286, [(0.9999999990288504, -4.3920366659448706e-05, 3.646956275561251e-06)], 1), (0.5299298132956617, [(-0.9999999924166296, 0.00012142298580281175, -2.0571809366343525e-05)], 1), (1.1021245929546457, [(0.9999999948276598, 9.227231804336238e-05, 4.278433956731682e-05)], 1)] [3]: #42 #juveniles in a given month will still be juveniles in the following month changed from 0.777 to 5 reduce2 = matrix(RDF, [[ 0 , 0 , 35315 ], [ 0.00003 , 5 , 0 ], [ 0 , 0.071 , 0.949 ]]) reduce2 . eigenvectors_right() [3]: [(5.003707552922965, [(0.9999672546523404, 0.008091325535433357, 0.00014168324238369117)], 1), (0.016180003774550276, [(-0.999999999981778, 6.019479038603754e-06, -4.5816236087371984e-07)], 1), (0.9291124433024828, [(0.9999999996267567, -7.3694003017710476e-06, 2.6309286222729642e-05)], 1)] [4]: #42 #fraction of larvae that survive to become juveniles changed from 0.00003 to 1.678 reduce3 = matrix(RDF, [[ 0 , 0 , 35315 ], [ 1.678 , 5 , 0 ], [ 0 , 0.071 , 0.949 ]]) reduce3 . eigenvectors_right() [4]: [(18.280142630206228, [(-0.9921115248098542, -0.12535732371159636, -0.0005135477892848791)], 1), (-6.165571315103122 + 13.861665716354738*I, [(0.995585586641781, -0.058876872223942875 - 0.07309357471828473*I, -0.00017381718631540906 + 0.0003907822340096069*I)], 7
1), (-6.165571315103122 - 13.861665716354738*I, [(0.995585586641781, -0.058876872223942875 + 0.07309357471828473*I, -0.00017381718631540906 - 0.0003907822340096069*I)], 1)] [0]: #42 the biggest reduction in growth rate came from the fraction of larvae that survive to become juveniles (from 0.15 to 18.3) [32]: #43 original target vector @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 1 , 1 ])): u = r * vector([ 1 , 2 ]) v = s * vector([ 1 , 0.5 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [32]: Interactive function <function coordinatesystem at 0x7fa9b48f84c0> with 3 widgets r: IntSlider(value=0, desc… [35]: #43 new approaching point @interact def coordinatesystem2 (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 2 , 3 ])): u = r * vector([ 1 , 2 ]) v = s * vector([ 1 , 0.5 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [35]: Interactive function <function coordinatesystem2 at 0x7fa9b5235ee0> with 3 widgets r: IntSlider(value=0, des… [36]: #43 new approaching point @interact def coordinatesystem3 (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ -5 , 1.2 ])): u = r * vector([ 1 , 2 ]) v = s * vector([ 1 , 0.5 ]) 8
calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [36]: Interactive function <function coordinatesystem3 at 0x7fa9b4c1c430> with 3 widgets r: IntSlider(value=0, des… [37]: #43 new approaching point @interact def coordinatesystem3 (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ -4 , -8 ])): u = r * vector([ 1 , 2 ]) v = s * vector([ 1 , 0.5 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [37]: Interactive function <function coordinatesystem3 at 0x7fa9b52354c0> with 3 widgets r: IntSlider(value=0, des… [38]: #43 new approaching point @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 3 , -2.4 ])): u = r * vector([ 1 , 2 ]) v = s * vector([ 1 , 0.5 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [38]: Interactive function <function coordinatesystem at 0x7fa9b49a1280> with 3 widgets r: IntSlider(value=0, desc… [39]: #44 new axis vectors [0,5] and [2,3.6] @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 2 , 3 ])): u = r * vector([ 0 , 5 ]) 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
v = s * vector([ 2 , 3.6 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [39]: Interactive function <function coordinatesystem at 0x7fa9b49ef4c0> with 3 widgets r: IntSlider(value=0, desc… [40]: #44 @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ -5 , 1.2 ])): u = r * vector([ 0 , 5 ]) v = s * vector([ 2 , 3.6 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [40]: Interactive function <function coordinatesystem at 0x7fa9b4793ca0> with 3 widgets r: IntSlider(value=0, desc… [41]: #44 @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ -4 , -8 ])): u = r * vector([ 0 , 5 ]) v = s * vector([ 2 , 3.6 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [41]: Interactive function <function coordinatesystem at 0x7fa9b4c1c9d0> with 3 widgets r: IntSlider(value=0, desc… [42]: #44 @interact def coordinatesystem (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 3 , -2.4 ])): 10
u = r * vector([ 0 , 5 ]) v = s * vector([ 2 , 3.6 ]) calculate = u + v p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(calculate, color = "red" ) + plot(target, color = "orange" ) + point(target, size =50 , color = "purple" ) show(p) [42]: Interactive function <function coordinatesystem at 0x7fa9b5104a60> with 3 widgets r: IntSlider(value=0, desc… [31]: #45 @interact def mycoordinatefunction (r = ( -10 , 10 ), s = ( -10 , 10 ), target = vector([ 2 , 3 ])): u = r * vector([ 1 , 1 ]) v = s * vector([ 2 , 2 ]) calculate = [(u[ 0 ] + v[ 0 ], u[ 1 ] + v[ 1 ])] p = plot(u, axes_labels = [ "x" , "y" ]) + plot(v, color = "pink" ) + plot(u + v, color = "yellow" ) + list_plot(calculate, size =50 , color = "orange" ) + point(target, size =50 , color = "red" ) show(p) show(calculate) [31]: Interactive function <function mycoordinatefunction at 0x7fa9b4e70f70> with 3 widgets r: IntSlider(value=0, … [0]: [0]: [0]: [0]: [0]: [0]: [0]: [0]: [0]: 11