(11C) Rabbits VS Foxes Simulation
07-29-2018, 06:46 AM (This post was last modified: 02-20-2020 12:39 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 700 Joined: Dec 2016
(11C) Rabbits VS Foxes Simulation
This program was modify from the promotional ad for the
HP-25 Scientific Programmable calculator.

A simple ecological model of interacting populations consists of rabbits with an infinite food supply and foxes that prey on them.
The system can be approximated by a pair of nonlinear, first-order differential equations.

This program simulate the population between the rabbit and fox given the number of rabbits and the number of foxes.

Example:
α = 0.01 // STO 0 // Frequency (how often rabbits and foxes meet)
h = 0.02 // STO 1 // Step size
r = 300 // Rabbits
f = 150 // Foxes

In Run mode: Clear REG
,01 STO 0
,02 STO 1
300 [ENTER] 150 f [A]

Display keep going:
303,00156 // 303 are Rabbits and 156 are Foxes
305,00162
307,00169
309,00176
311,00183
312,00191
312,00199
.
.
.
Simulation keep going for observation........
Press any keys except [ON] to stop.
Press [R/S] to continue.

User can turn off the calculator and keep continue from where you stop the last time simply press [R/S] assuming that the storage registers haven't been change.

Program: Rabbits VS Foxes Populations
Code:
 LBL A STO 2 Rv STO 3 FIX 5 LBL 0 RCL 2 ENTER ENTER RCL 3 RCL 0 x x STO 4 X<>Y - RCL 1 x + X<0 ? 0 STO 2 RCL 3 2 x RCL 4 - RCL 1 x RCL 3 + X<0 ? 0 STO 3 INT RCL 2 INT EEX 5 ÷ + PSE PSE GTO 0

Gamo
07-29-2018, 08:42 AM
Post: #2
 Leviset Member Posts: 144 Joined: Aug 2015
RE: (11C) Rabbits VS Foxes Simulation
There was a beautiful colour version of this, complete with Pi Charts on cassette that came with the ZX Spectrum in 1982

Denny
07-29-2018, 12:07 PM
Post: #3
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
(07-29-2018 06:46 AM)Gamo Wrote:  The system can be approximated by a pair of nonlinear, first-order differential equations.

From the code I assume they are:
$\begin{eqnarray} \dot{r}&=2r-\alpha fr \\ \dot{f}&=\alpha fr-f \end{eqnarray}$

This looks very much like the Lotka–Volterra equations:
\begin{aligned} \frac {dx}{dt}&=\alpha x-\beta xy\\ \frac {dy}{dt}&=\delta xy-\gamma y \end{aligned}

What is reason for the peculiar factor 2 in $$\dot{r}=2r-\alpha fr$$?

At a stationary point the derivative vanishes: $$\dot{r}=\dot{f}=0$$.
\begin{aligned}
r(2-\alpha f)=0&\Rightarrow &f=\frac{2}{\alpha}\\
f(\alpha r-1)=0&\Rightarrow &r=\frac{1}{\alpha}
\end{aligned}

Thus for the value given $$\alpha=0.01$$ we end up with:
\begin{aligned}
r=100\\
f=200
\end{aligned}

This looks like a lot of foxes compared to the rabbits.

Cheers
Thomas
07-29-2018, 02:03 PM
Post: #4
 Gamo Senior Member Posts: 700 Joined: Dec 2016
RE: (11C) Rabbits VS Foxes Simulation
Thanks Thomas Klemm

I was adapting this program to work for 11C and I don't know why that factor of 2 is for but I guess is that the rabbit reproduce faster than a fox?

Gamo
07-29-2018, 10:51 PM (This post was last modified: 07-29-2018 10:51 PM by SlideRule.)
Post: #5
 SlideRule Senior Member Posts: 1,313 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
The source document?
[attachment=6168]

BEST!
SlideRule
07-30-2018, 05:58 AM
Post: #6
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
Thanks a lot for providing the original source.

It's a bit disturbing that the phase-space plot doesn't show closed curves.
But that might be due to using a simple Euler method.
I wonder if using Runge–Kutta methods would even fit the 49 steps available.

Cheers
Thomas
07-30-2018, 09:47 AM (This post was last modified: 07-30-2018 10:43 AM by SlideRule.)
Post: #7
 SlideRule Senior Member Posts: 1,313 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
(07-30-2018 05:58 AM)Thomas Klemm Wrote:  Thanks a lot for providing the original source.

My apologies ALL for providing an un-referenced extract:
An Example of HP-25 Programming: Hewlett-Packard Journal, Vol. 27 No. 3, 1975-11, page 6 [attachment=6172]

The Predator-Prey Model: Science and Engineering for the Commodore 64, pages 261-271 [attachment=6169]

Rabbits and Foxes: Biological Population Cycles: Creative Computing 1983-06, pages 280 & 282 [attachment=6170]

Introduction to Mathematical Control Theory: Clarendon Press, pages 10, 19-20, 102, 117 & 145 [attachment=6171]

BEST!
SlideRule
07-30-2018, 01:03 PM
Post: #8
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
It gets better and better …
07-30-2018, 01:13 PM
Post: #9
 Gamo Senior Member Posts: 700 Joined: Dec 2016
RE: (11C) Rabbits VS Foxes Simulation
Thanks SlideRule

Thank You for the extra detail information on this topic, very interesting.

Gamo
07-30-2018, 11:43 PM (This post was last modified: 07-30-2018 11:45 PM by SlideRule.)
Post: #10
 SlideRule Senior Member Posts: 1,313 Joined: Dec 2013
RE: (11C) Rabbits VS Foxes Simulation
(07-29-2018 08:42 AM)Leviset Wrote:  There was a beautiful colour version of this, complete with Pi Charts on cassette that came with the ZX Spectrum in 1982

Alas, my old ZX tape system is defunct, so if you have equivalent but functional technology
[attachment=6173]
Foxes & Rabbites screen shot
[attachment=6174]
z80 program file ps: change zip extension to z80

BEST!
SlideRule
 « Next Oldest | Next Newest »

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