Post Reply 
Rabbit vs. Foxes
02-08-2020, 07:52 PM
Post: #2
RE: Rabbit vs. Foxes
Here is another variation on this program from Datafile V36N3P27 as presented at the HPCC Mini-Conference in October 2019. This version dispenses with the dialogue box entry of values, but adds saving the results in a matrix and hence plotting and exploring the results in the graphing environment.

[Image: Rabbits%20vs%20Foxes.png]

The Prime requires that you have opened the Statistics 2Var before entering the program, otherwise a syntax error is generated.

The complete graph of results (1125 iterations), as shown in the original HP magazine article, is drawn in approximately 0.33s on an HP Prime G2.

PHP Code:
EXPORT Rabbits_vs_Foxes()
BEGIN
 LOCAL α
:=0.01;
 
LOCAL h:=0.02;
 
LOCAL r0:=300;
 
LOCAL f0:=150;
 
LOCAL iterations:=1125;

 
LOCAL n;

 
LOCAL r:=MAKELIST(0,X,1,iterations);
 
LOCAL f:=MAKELIST(0,X,1,iterations);

 
r[1]:=r0;
 
f[1]:=f0;

 FOR 
n FROM 1 to iterations-DO
  
r[n+1]:=r[n]+h*(2*r[n]-α*r[n]*f[n]);
  
f[n+1]:=f[n]+h*(-f[n]+α*r[n]*f[n]); 
 
END;

 
STARTAPP("Statistics 2Var");
 
C1:=r;
 
C2:=f;
 
SetIndep(S1,C1);
 
SetDepend(S1,C2);
 
Connect:=1;
 
Fit:=0;
 
Xtick:=50;
 
Ytick:=50;
 
STARTVIEW(9);
END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Rabbit vs. Foxes - Eddie W. Shore - 02-08-2020, 02:26 PM
RE: Rabbit vs. Foxes - Mark Power - 02-08-2020 07:52 PM



User(s) browsing this thread: 1 Guest(s)