Group Abstract Group Abstract

Message Boards Message Boards

Predator Prey Plot over time

Posted 2 days ago

Hi;
I am trying to plot a progression of time periods for a Predator - Prey model using the function ParametricPlot with constants, Eigenvalues (raised to k powers and Eigenvectors - see attached notebook. However, I am having trouble getting any output. I am sure it is something that I am not coding correctly.

Thanks,
Mitch Sandlin

POSTED BY: Mitchell Sandlin
4 Replies

Using MatrixPower:

mat = {{6/10, 1/2}, {-(7/40), 6/5}};
eigen = Eigenvectors[mat];
f[t_] = MatrixPower[mat, t];
ParametricPlot[{f[t] . {1, 1},
  f[t] . eigen[[1]], f[t] . eigen[[2]],
  f[t] . {1, 0}}, {t, 0, 20}] /. Line -> Arrow
POSTED BY: Gianluca Gorni

ParametricPlot[] is evaluated before the c's are replaced by numbers. You need to do the replacement first.

If f and r are scalars, then you're plotting a scalar, which ParametricPlot[] won't do.

If f and r are ordered pairs, then you're plotting an ordered pair, and you should see a plot, if the first point is addressed.

You can also use Unevaluated[] to address the first point:

Unevaluated[
  ParametricPlot[Subscript[c, 1]*(0.95^k*{10, 7} . {f, r}) + 
         Subscript[c, 2]*(0.85^k*{2, 1} . {f, r}), {k, 1, 10}]] /. 
   {Subscript[c, 1] -> 1, Subscript[c, 2] -> 1, f -> {1, -1}, 
     r -> {-3, 2}}

Oops, update: Just noticed the blackboard. I think one problem, which is addressed incorrectly in the 2nd and 3rd points, is that you should not be using . (Dot[]) in your code. The blackboard as scalar multiplication (* or Times[]), not vector-vector multiplication nor matrix-vector multiplication.

POSTED BY: Michael Rogers
Posted 2 days ago

Not quite sure of what you want, but if you want to see a preditor-prey population pair evolve over time, you can use ParametricPlot, yes. The whole eigenvector business is just turning the matrix arithmetic into scalar arithmetic, which means you can use a simple variable in your ParametricPlot.

Block[
 {k},
 With[
  {m = {{6/10, 1/2}, {-7/40, 6/5}}},
  {initialPopulations = {20, 50}},
  {es = Eigensystem[m]},
  {lc = SolveValues[k . es[[2]] == initialPopulations, k \[Element] Vectors[2, Reals]]},
  populationFn = Function[t, Total[es[[1]]^t lc[[1]] es[[2]]]]]]

Demonstration:

populationFn[6.5] // N
(* {80.7071, 69.0127} *)
(* about 81 foxes and about 69 rabbits *)

ParametricPlot[populationFn[t], {t, 0, 10}]

enter image description here

Explanation:

You don't necessarily need the Block, but I'm using the variable k in the Solve, and I just want to avoid a conflict.

The m is simply your predator-prey discrete dynamical system. initialPopulations is just an initial condition that I made up: 20 foxes and 50 rabbits. We need an initial value before we can solve for the linear combination of eigenvectors that we'll be using.

I'm using Eigensystem as a shortcut rather than calculating the eigenvectors and eigenvalues separately.

The lc is the linear combination of the eigenvectors that give the initial value.

The output is a function, and we can plug it into ParametricPlot. I'm just doing the standard arithmetic inside the Function. Note how we've moved from applying the matrix to do updates to just using scalars.

This doesn't look like the picture you posted, but I'm not sure what you were going for anyway. Ask follow ups if this doesn't help.

POSTED BY: Eric Rimbey

I am trying to guess what f and r may be:

With[{c1 = 1, c2 = 1, f = 1, r = 1},
 Plot[c1*0.95^k {10, 7} . {f, r} +
   c2*0.85^k {2, 1} . {f, r}, {k, 1, 10}]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard