""" Exercise A.20 from a primer on. The same model as ex. A.19, but we use a for-loop to perform a parameter sweep and inspect the corresponding solutions. The exercise asks us to create separate plots and store them in file, but it is here modified to plot all the curves in the same window. This is usually more convenient, although the plot can get crowded. """ import numpy as np import matplotlib.pyplot as plt def logistic(y0, q, N): y = np.zeros(N + 1) y[0] = y0 for n in range(1, N + 1): y[n] = y[n-1] + q * y[n-1] * (1 - y[n-1]) plt.plot(y, label=f'y0={y0},q={q}') for y0 in 0.01, 0.3: for q in 0.1, 2, 3: logistic(y0, q, N=50) #Display the labels defined for each curve: plt.legend() plt.show()