(42S) Rabbits vs. Foxes
02-08-2020, 02:25 PM
Post: #1
 Eddie W. Shore Senior Member Posts: 1,236 Joined: Dec 2013
(42S) Rabbits vs. Foxes
Introduction

The program presented today is based on the Rabbits vs. Foxes program for the HP 25 (see source below). The program determines the population of rabbits and foxes over time as modeled by the differential equations:

Change in Rabbits:
dr/dt = 2 * r - α * r * f

Change of Foxes:
df/dt = -f + α * r * f

where:
r = population of rabbits
f = population of foxes
α = probability of a rabbit encounters a fox
h = step

This is approximated by Euler's method.

The HP Prime program RABBIT25 displays a print screen of results of the desired amount of iterations. The HP 42S program RAB25 displays the results one step at time in the format rrrrr.fffff (rabbits.foxes), like the original HP 25 program.

HP 42S/Free42/DM42 Program RAB25

Code:
00 { 58-Byte Prgm } 01▸LBL "RAB25" 02 STO 02 03 R↓ 04 STO 03 05 FIX 05 06▸LBL 05 07 RCL 02 08 ENTER 09 ENTER 10 RCL 03 11 RCL 00 12 × 13 × 14 STO 04 15 X<>Y 16 - 17 RCL 01 18 × 19 + 20 X<0? 21 0 22 STO 02 23 RCL 03 24 2 25 × 26 RCL 04 27 - 28 RCL 01 29 × 30 RCL 03 31 + 32 X<0? 33 0 34 STO 03 35 IP 36 RCL 02 37 IP 38 1ᴇ5 39 ÷ 40 + 41 STOP 42 GTO 05 43 .END.

Note: You can replace STOP with PSE, as many as you like, if you don't want to press R/S after each step.

Instructions:
Store α in R00, store h in R01, enter initial rabbit population

Example

Initial Populations:
Rabbits: r = 300
Fixes: f = 150
α = 0.01
h = 0.02

Iter: Rabbits.Foxes (rrrrr.ffff)
0: 300.00150
1: 303.00156
2: 305.00162
3: 307.00169
4: 309.00176
5: 311.00183
6: 312.00191
7: 312.00199
8: 312.00207
9: 312.00216
10: 311.00225
11: 309.00235
12: 307.00245
13: 304.00255
14: 301.00265
15: 297.00276

Source:

Randall B. Neff and Lynn Tilman "An Example of HP-25 Programming" Hewlett-Packard Journal: November 1975. pg. 6

Blog post: http://edspi31415.blogspot.com/2020/02/h...foxes.html
02-08-2020, 04:02 PM
Post: #2
 SlideRule Senior Member Posts: 1,313 Joined: Dec 2013
RE: (42S) Rabbits vs. Foxes
from an earlier post:

The Predator-Prey Model: Science and Engineering for the Commodore 64, pages 261-271
Rabbits and Foxes: Biological Population Cycles: Creative Computing 1983-06, pages 280 & 282
Introduction to Mathematical Control Theory: Clarendon Press, pages 10, 19-20, 102, 117 & 145

BEST!
SlideRule
02-08-2020, 05:23 PM
Post: #3
 PedroLeiva Member Posts: 183 Joined: Jun 2014
RE: (42S) Rabbits vs. Foxes
Link to Hewlett-Packard Journal NOV1975, with HP 25 program: https://www.hpl.hp.com/hpjournal/pdfs/Is...975-11.pdf
Pedro
 « Next Oldest | Next Newest »

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