Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
614 views
ubuntu2004
Kernel: Python 3 (system-wide)
import numpy as np import matplotlib.pyplot as plt r_X = 1 r_Y = 0.95 K_X = 1e6 n_hours = 24 initial_population = 1000 pop_X = np.zeros(n_hours + 1) pop_Y = np.zeros(n_hours + 1) pop_X[0] = initial_population for i in range(n_hours): pop_X[i + 1] = pop_X[i] + r_X * (1 - (pop_X[i] / K_X)) * pop_X[i] print("Population of species X:", pop_X)
Population of species X: [ 1000. 1999. 3994.003999 7972.05593006 15880.55818436 31508.92424047 62025.03617415 120202.9672359 225957.18113949 400857.71457048 641028.52181029 871139.47784629 983394.96583027 999724.27284022 999999.92397453 999999.99999999 1000000. 1000000. 1000000. 1000000. 1000000. 1000000. 1000000. 1000000. 1000000. ]
pop_Y[0] = initial_population for i in range(n_hours): pop_Y[i + 1] = pop_Y[i] + r_Y * (1 - (pop_Y[i] / K_X)) * pop_Y[i]
plt.figure(figsize=(6,3)) plt.plot(pop_X) plt.xlabel("time (hours)") plt.ylabel("population") plt.title("Species X")
Text(0.5, 1.0, 'Species X')
Image in a Jupyter notebook
plt.figure(figsize=(6,3)) plt.plot(pop_Y) plt.xlabel("time (hours)") plt.ylabel("population") plt.title("Species Y")
Text(0.5, 1.0, 'Species Y')
Image in a Jupyter notebook
data_X = np.loadtxt("data_exp_X.txt") data_Y = np.loadtxt("data_exp_Y.txt") plt.figure(figsize=(6,3)) plt.plot(pop_X, label="model") plt.plot(data_X, label="experiment") plt.xlabel("time (hours)") plt.ylabel("population") plt.title("Species X") plt.legend()
<matplotlib.legend.Legend at 0x7f1efcb917c0>
Image in a Jupyter notebook
plt.figure(figsize=(6,3)) plt.plot(pop_Y, label="model") plt.plot(data_X, label="experiment") plt.xlabel("time (hours)") plt.ylabel("population") plt.title("Species Y") plt.legend()
<matplotlib.legend.Legend at 0x7f1efcb01340>
Image in a Jupyter notebook
plt.figure(figsize=(6,3)) plt.plot(data_X, color='#ff7f0e')
[<matplotlib.lines.Line2D at 0x7f1efc8a53a0>]
Image in a Jupyter notebook