Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168742
Image: ubuntu2004
# EXPONENTIAL GROWTH: CONTINUOUS MODEL def exponential(N, r, x): return N * e**(r * x) plot(exponential(100., 0.25, x),(0,10))
plot(exponential(100., 0.25, x),(0,10), color = "blue") + plot(exponential(100., 0.15, x),(0,10), color = "red") + plot(exponential(100., 0.05, x),(0,10), color = "orange") + plot(exponential(100., -0.15, x),(0,10), color = "green")
# EXPONENTIAL GROWTH: DISCRETE MODEL def discrete_exp(N, lam): return N * lam n0 = 100 time = 100 pop_sizes = [n0] for years in range(1,time): pop_sizes.append(discrete_exp(pop_sizes[-1], 1.05)) plot_data = [] for years in range(len(pop_sizes)): plot_data.append([years, pop_sizes[years]]) points(plot_data)
line(plot_data)
line(plot_data, marker=".")
# EXPONENTIAL GROWTH: DISCRETE w/STOCHASTICITY def discrete_exp(N, lam, mu, sd): return N * (lam + gauss(mu, sd)) n0 = 100 time = 100 lam = 1.05 pop_sizes = [n0] mu = 0. sd = 0.25 for years in range(1,time): pop_sizes.append(discrete_exp(pop_sizes[-1], lam, mu, sd)) plot_data = [] for years in range(len(pop_sizes)): plot_data.append([years, pop_sizes[years]]) line(plot_data, marker = ".")
# LOGISTIC GROWTH: CONTINUOUS MODEL def log_growth(N0, K, r, t): return K/(1.+((K-N0)/N0)*exp(-r*t)) plot(log_growth(50, 250, 0.2, x), (0, 100), color = "blue") + plot(log_growth(400, 250, 0.2, x), (0, 100), color = "red")
# LOGISTIC GROWTH: DISCRETE MODEL def disc_log_growth(N, K, r): return N + N * r * (1 - N/K) time = 100 r = 2.58 K = 500 n0 = 20 pop_sizes = [n0] for years in range(1,time): pop_sizes.append(disc_log_growth(pop_sizes[-1], K, r)) plot_data = [] for years in range(len(pop_sizes)): plot_data.append([years, pop_sizes[years]]) line(plot_data, marker = '.')
time_lag = [] for years in range(len(pop_sizes)-1): time_lag.append([pop_sizes[years], pop_sizes[years+1]]) points(time_lag)