swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 430 forks source link

Correct solutions for "Simulating a dynamical system" (Ep. 16) #585

Closed alex-ball closed 2 years ago

alex-ball commented 2 years ago

The challenge "Simulating a dynamical system" in Episode 16 asks for values at times [0,1,...,t_final] but the solutions provide values at times [0,1,...,t_final - 1].

For example, in part two of the solution, population is initialized with the initial_population, and then the loop runs 9 times (range(1, 10)) to give a total of ten values, the last of which is the value at t = 9. A tenth run is needed to get what was asked for, so the loop should be:

for t in range(t_final):
    population.append( logistic_map(population[t], r) )

Happily, this looks even more like the function in part one, where you get the value at t + 1 in terms of the value at t, rather than the value at t in terms of the value at t - 1.

This PR supplies the corrected code for parts two and three, and the value of the population at t = 10, 100, 1000 instead of at t = 9, 99, 999.