For-Loop Exercise
Complete the missing pieces of the code below using the following description of a discrete logistic model. You can run the simulation and check your answers.
The discrete logistic growth model is:
Nt+1 = Nt + rNt(1 − Nt/K).
At each time step, the population changes according to a density-dependent
per-capita growth rate. Here,
r is the intrinsic growth rate for the continuous exponential growth (i.e. r + 1 = &lambda in the discrete exponential growth model), while
(1 − N/K) reduces that growth rate as the population approaches the
carrying capacity K.
Initialize the parameters below for running the simulation. The simulation uses your values, even though the example code below displays default values for demonstration.
| N0 | |
| r | |
| K | |
| end_time |
What is a vector? A vector is an ordered list of values. In this example, the first value stores the initial population size; the second value stores the population after one time step; the third value stores the population after two time steps, and so on. By storing the population size at every time step, we can later visualize the entire population trajectory.
Tips:
for loop. The code shown here is just one example.