This code was used to run the fish model in Problem 2.
%matplotlib inline import numpy as np from matplotlib import pyplot as plt migration_rate = np.loadtxt('fish_migration.txt') omegaMIN = 0.0009126 omegaONE = 0.000000001 rate_Coho = 5.6E6*(0.75)/365.25 #*0.75coho/fish * year/365.25 days max_Coho = 5.6E6*(0.75)*3.0 #*0.75coho/fish * 3 years arr_len = 60 dt = 1.0 model = np.zeros((arr_len,2)) rates = np.zeros((arr_len-1,3)) model[0,0]=1. model[0,1]=max_Coho for t in xrange(1,arr_len): model[t,0] = float(t)+1. rates[t-1,0] = rate_Coho rates[t-1,1] = -migration_rate[t-1,1] rates[t-1,2] = -(omegaMIN + omegaONE * model[t-1,1]) * model[t-1,1] model[t,1] = model[t-1,1] + dt * (sum(rates[t-1,:]) ) if model[t,1]<0: model[t,1]=0 plt.figure(1) plt.plot(model[:,0],model[:,1]) plt.xlabel('time [days]') plt.ylabel('populations [# of fish]') plt.ylim(0,max(model[:,1])) plt.figure(2) plt.plot(model[:-1,0],rates[:,0],label='stocking') plt.plot(model[:-1,0],-rates[:,1],label='migration out') plt.plot(model[:-1,0],-rates[:,2],label='death rate') plt.legend(loc='best') plt.xlabel('time [days]') plt.ylabel(r'$rate [\frac{fish}{days}]$') plt.show()