One way is to define the matrix a
and the list p
of
vectors of populations, initially containing just the vector
of initial populations:
sage: a = matrix(RR, 2, [1.02, -0.01, 0.03, 1.03])
sage: p = [vector(RR, 2, [300, 200])]
then extend the list by applying a number of times the matrix to the
last vector:
sage: for k in range(20):
....: p.append(a * p[-1])
then observe the evolution of populations:
sage: p
[(300.000000000000, 200.000000000000),
(304.000000000000, 215.000000000000),
(307.930000000000, 230.570000000000),
(311.782900000000, 246.725000000000),
(315.551308000000, 263.480237000000),
(319.227531790000, 280.851183350000),
(322.803570592300, 298.853544804200),
(326.271106556104, 317.503258266095),
(329.621496104565, 336.816489210761),
(332.845761134549, 356.809628770221),
(335.934580069538, 377.499290467364),
(338.878278766255, 398.902306583471),
(341.666821275745, 421.035724143963),
(344.289800459820, 443.916800506554),
(346.736428463951, 467.562998535545),
(348.995527047875, 491.991981345530),
(351.055517775377, 517.221606597332),
(352.904412064911, 543.269920328514),
(354.529801102924, 570.155150300316),
(355.918845621980, 597.895698842414),
(357.058265545995, 626.510135176345)]
or plot it as a set of points:
sage: point2d(p)
Launched png viewer for Graphics object consisting of 1 graphics primitive
or one could color the first point in red:
sage: point2d(p[0], color='red') + point2d(p[1:])
Launched png viewer for Graphics object consisting of 2 graphics primitives
or one could use line2d
instead of point2d
,
or one could use animate
to animate the evolution.
If you want to plot the evolution of each population:
sage: x, y = zip(*p)
sage: px = list_plot(x, color='green')
sage: py = list_plot(y, color='purple')
sage: px
Launched png viewer for Graphics object consisting of 1 graphics primitive
sage: py
Launched png viewer for Graphics object consisting of 1 graphics primitive
sage: px + py
Launched png viewer for Graphics object consisting of 2 graphics primitives