# 352 - Topic 01 - Population Models

## 1947 days ago by Professor352

Introduction to Differential Equations

John Travis

Mississippi College

This worksheet investigates the nature of solutions to increasingly complex population growth models.  Students can experiment with various parameters to find how each affects the nature of solutions.

# Worksheet still under development. Use at your own risk! 8-o
# This version attempts to solve the DE exactly t = var('t') # define an independent variable t P = function('P',t) # define x to be a function of that variable @interact def _(k=slider(1/10,1,1/10,1/2,label='$k$')): G = Graphics() P0 = [0.5,1.0,1.5,2.0,2.5,3.0] # initial population choices f = k*P DE = diff(P, t) - f for p0 in P0: soln = desolve(DE, [P,t],ics=(0,p0)) G += plot(soln,(t,0,3)) html('Exponential Population growth with no constraints\n\n') html('<center>Solution trajectories for\n${dP}/{dt}=%s$'%str(latex(f))+'\nusing various initial conditions.</center>') html('<center>The top exact solution is given by $P(t)=%s$</center>'%str(latex(soln))) show(G,xmin=0,xmax=3,ymin=0,ymax=10)

## Click to the left again to hide and once more to show the dynamic interactive window

# This cell shows the direction field and one solution curve t,p = var('t,p') # define an independent variable t and dep p P = function('P',t) # define x to be a function of that variable G = Graphics() p0 = 1.3 # Initial condition f = t-p0*P # Use capital P for this symbolic work f1 = t-p0*p # Use lower P for this numerical work DE = diff(P, t) - f G += plot_slope_field(f1,(t,0,3),(p,0,10)) soln = desolve(DE, [P,t],ics=(0,p0)) G += plot(soln,(t,0,3)) show(G,xmin=0,xmax=3,ymin=0,ymax=10)  t,p = var('t p') P = function('P',t) soln = desolve(diff(P,t)-(1/2)*P, [P,t],ics=(0,4)) G = plot_slope_field(t-(1/2)*p, (t,0,3), (p,0,18)) G += plot(soln,(t,0,3),color='red') G.show()  # Look at just normal geometric growth a = 1 growth_rate = 2 for k in range(10): a=growth_rate*a print a
 2 4 8 16 32 64 128 256 512 1024 2 4 8 16 32 64 128 256 512 1024
# This version attempts to solve the DE exactly # Suffers from solve issues with the symbolic solver # Logistic Growth Model t = var('t') # define an independent variable t P = function('P',t) # define x to be a function of that variable @interact def _(k=slider(1/10,1,1/10,1/2,label='$k$')): G = Graphics() P0 = [0.5,1.0,1.5,2.0,2.5,3.0] # initial population choices f = k*P*(1-P) DE = diff(P, t) - f for p0 in P0: soln = desolve(DE, [P,t],ics=(0,p0)) G += plot(soln,(t,0,3)) html('Logistic Population growth\n\n') html('<center>Solution trajectories for\n${dP}/{dt}=%s$'%str(f)+'\nusing various initial conditions.</center>') html('<center>The top exact solution is given by $P(t)=%s$</center>'%str(latex(soln))) show(G,xmin=0,xmax=3,ymin=0,ymax=10)

## Click to the left again to hide and once more to show the dynamic interactive window

# John Travis # Mississippi College # here is a numerical solver using splines on numerical trajectories. Needs to be faster. t,P = var('t,P') # define an independent variable t var('k,M,N,C') models = ['Exponential Growth','Logistic Growth','Logistic Growth with Sustainability','Logistic Growth with Harvesting'] @interact def _(k=slider(0.1,1.0,0.1,0.5,label='$k$'), model=models, M=input_box(1,width=10,label='Carrying capacity'), N=input_box(4/10,width=10,label='Sustainability min.'), C=input_box(1/10,width=10,label='Harvesting level')): t1 = 5 if (model==models): method=0 elif (model==models): method=1 elif (model==models): method=2 else: method=3 F = [k*P,k*P*(1-P/M),k*P*(1-P/M)*(P-N),k*P*(1-P/M)-C] flatex = ['$dP/dt = kP$','$dP/dt = kP(1-P/M)$','$dP/dt = kP(1-P/M)(P-N)$','$dP/dt = kP(1-P/M)-C$'] v = [] pts = Graphics() P0 = [n/10 for n in range(1, 21)] # initial population choices f = F[method] for p0 in P0: soln = desolve_rk4(f,P,ics=[0,p0],ivar=t,end_points=t1,step=0.25) pts += plot(spline(soln),0,t1) v.append(pts) pts.show() # animate(v,xmin=0,xmax=t1,ymin=0,ymax=2*M).show() html('<center>Solution trajectories for\n'+flatex[method]+'\nusing various initial conditions.</center>')

## Click to the left again to hide and once more to show the dynamic interactive window