Lotka-Volterra Predator-Prey
The classic 1925/1926 predator-prey equations, integrated with RK4 by OnlyCSharp.Biology.Ecology.LotkaVolterra. Prey grow, predators eat prey and grow, predators starve without prey - producing the famous lagged oscillation. Every number is computed live at build time (5001 integration points, step 0.01).
Parameters
- prey0 = 10 pred0 = 5
- alpha = 1 (prey growth) beta = 0.1 (predation)
- gamma = 1.5 (predator death) delta = 0.075 (predator growth per prey)
- tEnd = 50 stepSize = 0.01
Physics sanity check (conserved quantity)
V(N,P) = delta*N - gamma*ln(N) + beta*P - alpha*ln(P) is a first integral of the flow: exactly constant along a true trajectory. RK4 drift over 5001 steps should be tiny.
| Quantity | Value |
|---|---|
| V(initial) N=10.0000, P=5.0000 | -3.8133155519 |
| V(final) N=15.0213, P=3.3588 | -3.8133155509 |
| difference (should be ~0) | 1.016752E-009 |
Population over time
Sampled every 100th point (~1.0 time unit). The bar columns are proportional cell widths: prey (#) and predator (*) populations rendered as table-cell bars.
| t | prey | predator | prey level | predator level |
|---|---|---|---|---|
| 0.00 | 10.000 | 5.000 | ||
| 1.00 | 18.635 | 3.109 | ||
| 2.00 | 35.314 | 5.061 | ||
| 3.00 | 31.846 | 19.704 | ||
| 4.00 | 10.079 | 17.701 | ||
| 5.00 | 8.293 | 7.419 | ||
| 6.00 | 13.512 | 3.602 | ||
| 7.00 | 26.578 | 3.414 | ||
| 8.00 | 40.562 | 10.532 | ||
| 9.00 | 16.750 | 22.885 | ||
| 10.00 | 8.007 | 11.416 | ||
| 11.00 | 10.208 | 4.852 | ||
| 12.00 | 19.164 | 3.098 | ||
| 13.00 | 36.011 | 5.308 | ||
| 14.00 | 30.574 | 20.388 | ||
| 15.00 | 9.780 | 17.167 | ||
| 16.00 | 8.385 | 7.160 | ||
| 17.00 | 13.869 | 3.534 | ||
| 18.00 | 27.293 | 3.487 | ||
| 19.00 | 40.419 | 11.210 | ||
| 20.00 | 15.905 | 22.631 | ||
| 21.00 | 7.967 | 11.006 | ||
| 22.00 | 10.426 | 4.711 | ||
| 23.00 | 19.708 | 3.093 | ||
| 24.00 | 36.683 | 5.579 | ||
| 25.00 | 29.275 | 21.013 | ||
| 26.00 | 9.510 | 16.634 | ||
| 27.00 | 8.487 | 6.913 | ||
| 28.00 | 14.240 | 3.470 | ||
| 29.00 | 28.019 | 3.569 | ||
| 30.00 | 40.164 | 11.924 | ||
| 31.00 | 15.119 | 22.323 | ||
| 32.00 | 7.941 | 10.610 | ||
| 33.00 | 10.655 | 4.577 | ||
| 34.00 | 20.268 | 3.093 | ||
| 35.00 | 37.325 | 5.875 | ||
| 36.00 | 27.963 | 21.572 | ||
| 37.00 | 9.267 | 16.105 | ||
| 38.00 | 8.598 | 6.676 | ||
| 39.00 | 14.624 | 3.412 | ||
| 40.00 | 28.755 | 3.661 | ||
| 41.00 | 39.792 | 12.672 | ||
| 42.00 | 14.392 | 21.970 | ||
| 43.00 | 7.928 | 10.228 | ||
| 44.00 | 10.895 | 4.450 | ||
| 45.00 | 20.844 | 3.098 | ||
| 46.00 | 37.931 | 6.199 | ||
| 47.00 | 26.654 | 22.057 | ||
| 48.00 | 9.050 | 15.583 | ||
| 49.00 | 8.718 | 6.449 | ||
| 50.00 | 15.021 | 3.359 |
Reading it
Prey rise, then predators rise chasing them, then prey crash from over-predation, then predators starve and crash too - and the cycle repeats. The predator peak always lags the prey peak: that lag is the signature of the predator-prey cycle.