411 REFERENCE · Wikibooks
Scientific Calculations with Julia/Population Growth
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Scientific Calculations with Julia Population Growth Game Theory Land Cultivation
Growth Model
Assuming that the number of individuals in a population is a continuous function of time that has a continuous derivative, we have that the population growth over time can be represented by the derivative of , which in a basic model can be assumed to be directly proportional to the number of individuals in the population.
We therefore have the following differential equation:
with : Malthusian growth parameter (maximum population growth rate).
Therefore, if is a constant, the population grows exponentially with a slope dependent on .
Instead, in an environment with limited resource availability, population evolution can be described using a coefficient that decreases as the population increases: the simplest model is with and constants. Substituting this function into the previous differential equation yields:
which can be written in the form:
with , which is the so-called maximum sustainable population, and equal to the Malthusian growth parameter.
This is Verhulst's logistic equation.
Separating the variables, we obtain:
thumb|Differential Equation Solution
Solving the integrals, choosing as primitives those such that and using the properties of logarithms, we obtain the solution:
Note that due to overcrowding, the population no longer grows exponentially but converges to the asymptotic value regardless of .
The solution to the equation can also be written in the following forms:
It is easy to verify that this solution has two horizontal asymptotes:
A different behavior occurs in the case , where the second limit would tend to , also presenting a vertical asymptote, but these solutions are not considered in the growth model (they evidently describe a rapidly growing population). (Decrease because it is initially in excess of available resources.)
Example calculation with Julia
Suppose a rabbit population is growing at a rate of 30% per month. Suppose the initial population consists of two rabbits.
a. How many rabbits will there be after 1 year?
b. How long will it take for the population to reach 1,000?
First, you need to install the Plots and DifferentialEquations packages.
From the REPL, type:
using Pkg
Pkg.add("Plots")
using Pkg
Pkg.add("DifferentialEquations")
From Jupyter, in two code cells, type:
] add Plots
] add DifferentialEquations
and then click Run. Then run the code to solve the differential equation and plot the analytical and numerical solution of exponential Malthusian growth (I use the following code released under the MIT license: https://computationalmindset.com/en/neural-networks/ordinary-differential-equation-solvers-in-julia.html):
using DifferentialEquations
using Plots
ode_fn(N,p,t) = 0.3N
an_sol(t) = 2*exp(0.3*t)
t_begin=0.0
t_end=20.0
tspan = (t_begin,t_end)
x_init=2.0
prob = ODEProblem(ode_fn, x_init, tspan)
num_sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
plot(num_sol.t, an_sol.(num_sol.t),
linewidth=2, ls=:dash,
title="Malthusian Growth via DifferentialEquations",
xaxis="t", yaxis="N",
label="analytic",
legend=true)
plot!(num_sol,
linewidth=1,
label="numeric")
After 1 year, there will be 73 rabbits, while 600 rabbits will be obtained after 19 months:
num_sol(12)
73.19646891230852
using Roots
y(t)=2*exp(0.3*t)-600;
find_zero(y,18)
19.012608248854004
If available resources are limited, growth will no longer be exponential but will reach, for example, a limit of 1,500 rabbits using the logistic equation calculated with Julia and displayed in a graph:
orde_fn(N,p,t) = 0.3N*(1-N/1500)
an_sol(t) = 1500/(1+(1500/2-1)*exp(-0.3*t))
t_begin=0.0
t_end=50.0
tspan = (t_begin,t_end)
x_init=2.0
prob = ODEProblem(ode_fn, x_init, tspan)
num_sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
plot(num_sol.t, an_sol.(num_sol.t),
linewidth=2, ls=:dash,
title="Logistic Equation via DifferentialEquations",
xaxis="t", yaxis="N",
label="analytical",
legend=true)
plot!(num_sol,
linewidth=1,
label="numeric")
thumb|center|500px