Population dynamics 3

Control loops

The carrying capacity of a population is the maximum amount of a species that an ecosystem can support in relation to factors such as nesting sites, food, etc. To calculate the population size while considering the carrying capacity of the environment, we use the logistic growth equation:

\[\frac{dN}{dt} = r*N*(1-NK)\]

With the solution

\[N_t = \frac{K}{1 + (\frac{K}{N_0}-1)* e^{-r*t}}\]

with N_t representing the size of the population at time t, N_0 as the size of the population at time 0, r as the growth rate, t as the time at which you want to calculate the population size, and K as the carrying capacity of the environment.

When the population is small relative to the carrying capacity (N≪K), the growth is almost exponential (similar to unlimited growth). As the population size approaches the carrying capacity (N∼K), the growth rate decreases. Eventually, the population stabilizes at the carrying capacity level.

Since the population of African elephants in Kruger National Park is rising sharply, we want to determine when the population reaches 99% of the carrying capacity. We will do this automatically using a for loop and a while loop.

Assignments

Write a Python script that includes the following functionalities.

  1. Ask the user to input the following values:
  1. Implementent a for-loop to calculate the population size for the first 5 years and print it in the following format:

    Time point 1 – population size: 46384

    Use the following formula to calculate the population size:

\[N_t = \frac{K}{1 + (\frac{K}{N_0}-1)* e^{-r*t}}\]
  1. Implement a for-loop to calculate the population size for each time step. Ensure that the time values increase from 1 to t in increments of 5 years, where t is the time specified by the user. Calculate at which time point (in years) 99% of the carrying capacity is exceeded. If this occurs, the loop should stop, and the message should appear:

    99% of the carrying capacity was reached Number of years 160 - population size: 49515

Example

Input:

    >>>Enter the growth rate: 0.3
    >>>Enter the initial size of the population: 100
    >>>Enter the time (in years) for which you want to determine the number of individuals: 40
    >>>Enter the carrying capacity: 100

Output:

    Time point 1 - population size: 64
    Time point 2 - population size: 76
    Time point 3 - population size: 85
    Time point 4 - population size: 91
    Time point 5 - population size: 95
    99% of the carrying capacity was reached
    Number of years 10 - population size: 99