A brief note on Growth and Populations by Computer . Read it before a test. Try each question at the end before you open its answer.
Exponential growth A loop doubles with N = 2 * N; the formula N0 * 2 ** (t / T) jumps to any time and works on numpy arrays. With a growth rate: N = N 0 e r t N = N_0 e^{rt} N = N 0 e r t , and T = ln 2 r T = \dfrac{\ln 2}{r} T = r ln 2 . Use np.log and np.exp, not np.log10. On a log axis, plt.yscale("log"), exponential growth is a straight line. Logistic growth d N d t = r N ( 1 − N K ) \dfrac{dN}{dt} = rN\left(1 - \dfrac{N}{K}\right) d t d N = r N ( 1 − K N ) : nearly exponential while N N N is small, stopping at the carrying capacity K K K . An Euler step: N = N + r * N * (1 - N / K) * dt. Keep dt much smaller than 1 r \dfrac{1}{r} r 1 . The S-curve grows fastest at K 2 \dfrac{K}{2} 2 K , at r K 4 \dfrac{rK}{4} 4 r K , and reaches it at t = ln ( K / N 0 − 1 ) r t = \dfrac{\ln(K/N_0 - 1)}{r} t = r ln ( K / N 0 − 1 ) . Fitting np.polyfit(t, np.log(N), 1) gives the slope r r r and the intercept ln N 0 \ln N_0 ln N 0 of exponential counts. curve_fit(model, t, N, p0=guess) returns the best parameters in the order of the model's arguments after t. A fit makes the sum of squared misses smallest. A worked example What does this print?
Hour 1. 40 + 0.5 × 40 × 0.9 = 58 40 + 0.5 \times 40 \times 0.9 = 58 40 + 0.5 × 40 × 0.9 = 58 . Hour 2. 58 + 0.5 × 58 × 0.855 = 82.795 58 + 0.5 \times 58 \times 0.855 = 82.795 58 + 0.5 × 58 × 0.855 = 82.795 . Hour 3. 82.795 + 0.5 × 82.795 × 0.793 = 115.6 82.795 + 0.5 \times 82.795 \times 0.793 = 115.6 82.795 + 0.5 × 82.795 × 0.793 = 115.6 . It prints 116.
Practice with new numbers
A program to try The program grows the same population exponentially and logistically, side by side, and prints both every two hours.
Run it. After how many hours do the two columns clearly part?
1. Change K to 3000 cells. When do they part now?
Mistakes to avoid ^ for a power. In Python a power is **. Hours and minutes mixed. Keep t t t , T T T and d t dt d t in the same unit as r r r . No dt in the step. Without it, each step is one whole unit of time. A line fitted to N. Fit the line to ln N \ln N ln N . The time not first. curve_fit puts the times into the model's first argument. Check yourself A culture of 25 25 25 cells doubles every 12 12 12 min. How many cells are there after one hour? Stuck? Show a hint Show the answerWhat is the doubling time for r = 0.2 r = 0.2 r = 0.2 per hour? Stuck? Show a hint Show the answerA logistic population has K = 600 K = 600 K = 600 cells. At what count is it growing fastest? Stuck? Show a hint Show the answerWhy fit a straight line to ln N \ln N ln N and not to N N N ? Stuck? Show a hint Show the answer