# prize35-6 Exercise 2: where is logistic growth fastest? def run(r, K=500, start=10, years=40): n = float(start) best_year, best_growth, best_n = 0, 0.0, n for year in range(years + 1): growth = r * n * (1 - n / K) if growth > best_growth: best_year, best_growth, best_n = year, growth, n n = n + growth return best_year, best_growth, best_n, n for r in (0.8, 0.2): year, growth, n_at, final = run(r) print(f"r = {r}: fastest growth {growth:.1f} per year in year {year} at N = {n_at:.0f}; N after 40 years = {final:.0f}") # Output: # r = 0.8: fastest growth 99.9 per year in year 6 at N = 242 # r = 0.2: fastest growth 25.0 per year in year 21 at N = 257 # (N after 40 years: 500 and 494) # Reading it: with either rate the fastest growth happens at roughly half the carrying capacity (K/2 = 250), # and the peak growth is about r*K/4 (100 and 25). A higher r only gets there sooner; it does not change # where the peak is or where the population ends up. The small differences from 250 come from stepping # in whole years. The slow r = 0.2 population has not quite reached K after 40 years (494).