Using Python You want to model a population N that grows according to \"logistic
ID: 3823871 • Letter: U
Question
Using Python
You want to model a population N that grows according to "logistic growth", defined mathematically as dN/dt = rN(1-N/Nmax). Write a python program that solves (integrates) dN/dt using using Euler's method. Euler's method iteratively estimates a variable across an integration interval [t0-tend] from derivative values (dy/dt) using the following formula: y(t+h) = y(t)+h*(dy/dt) Euler Image Your program should solve for y for time starting at 0 and ending at 100. Assume r=0.12, and Nmax=100. Use a stepsize (h) of 0.01. Initially, assume N (at t=0) is 1. As your output, generate a chart of N(t)
thanks
Explanation / Answer
Python 2.7 code:
r=0.12
Nmax=100.0
h = 0.01;
size = int(100/0.01);
y = [];
x = []
for i in range(0,size):
x.append(i*0.01)
y.append(0.0)
y[0] = 1;
for n in range(0,size-1):
y[n+1] = y[n] + h*( r*y[n]*(1-(y[n])/Nmax));
print "N(", n+1, ")= ", y[n+1]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.