Caswell Ex. 2.2 - 02/23/2010

703 days ago by bmc.ppais

# -*- coding: utf-8 -*- # Name: Caitlin Evans, Priscy Pais # Course: CS250 - Computational Methods # Date: 02/23/10 # Purpose: Recreating Example 2.2 from Caswell ch 2 - 10 populations # CODING DONE IN PYTHON! import numpy as np import matplotlib.pyplot as plt from random import * A = np.array([[0., 1., 5.], [0.3, 0., 0.], [0., 0.5, 0.]]) # list of initial values for multiple populations n0 = [] for i in range(10): n0.append([randrange(0, 20)*1.0, randrange(0, 20)*1.0, randrange(0, 20)*1.0]) for i in range(10): n_t = n0[i] Lizards = [n_t] # for time range 0 - 15 for j in range(1,16): n_t = np.dot(A, n_t) Lizards.append(n_t) #print "Population at time", i #print Lizards plt.plot(range(len(Lizards)), Lizards) plt.show() # log values for time range 0 - 60 #Lizards_sum = [sum(n_t)] #for j in range(1,60): #n_t = np.dot(A, n_t) #Lizards.append(n_t) #Lizards_sum.append(sum(n_t)) ##print Lizards #plt.semilogy(range(len(Lizards_sum)), Lizards_sum) #plt.show() # proportions for time range 0 - 40 #prop = [] # master list of proportions for each age class over N time steps - list of lists #temp = [] # temporary list to hold proportion of each age class for a single time step #for i in range(3): #temp.append(Lizards[0][i]/sum(Lizards[0])) #prop.append(temp) ##print prop #for i in range(1,40): #temp = [] #n_t = np.dot(A, n_t) #Lizards.append(n_t) #for j in n_t: #temp.append(j / sum(n_t)) #prop.append(temp) ##print "Lizards list:" ##for i in Lizards: ##print i ##print "Proportions list:" ##for i in prop: ##print i #plt.plot(range(len(prop)), prop) #plt.show()