Professional Documents
Culture Documents
Lab10 Assignment LavanyaBahri 100799787
Lab10 Assignment LavanyaBahri 100799787
April 5, 2021
0.2 Task 1
[ ]: #Created on Monday 5th April 2021
#@author: Lavanya Bahri(100799787)
#Lab 09 - Jupyter Notebook
Your function will collect the counts of each species in two lists: predatorCounts and preyCounts.
The function will have a loop, representing rounds of the simulation, which repeats until one of
1
the values (predator or prey) is zero. At each iteration, you will update the count, and append
these counts to the predatorCounts and preyCounts lists, of predators and prey according to the
following formulae:
preyi+1 = preyi × (1 + preyGrowth − predationRate × predatorsi )
predatorsi+1 = predatorsi × (1 − predShrink + predF edBrithRate × preyi )
0.4 Notes
Note 1: preyi+1 is merely a Mathematical notation to show the relationship with how the values
change from one round to the next. You cannot use this notation in Python.
Note 2: preyi+1 is the number of prey on the current timestep, and preyi is the number of prey
on the previous timestep. You should have a variable called prey for this purpose. Similarly,
predatorsi+1 is the number of predators on the current timestep, and predatorsi is the number of
predators on the previous timestep. You should have a variable called predators for this purpose.
Once the simulation ends, draw a plot comparing the number of predator and prey over time.
def␣
,→Simulate(initialPred,initialPrey,preyGrowth,predationRate,predShrink,predFedBirthRate):
,→
preyCounts=[initialPrey]
predatorCounts=[initialPred]
i=0
while True:
Prey = preyCounts[i]*(1+preyGrowth-(predationRate*predatorCounts[i]))
␣
,→Predators=predatorCounts[i]*(1-predShrink+(predFedBirthRate*preyCounts[i]))
plot1=plt.plot(range(len(preyCounts)),preyCounts, "c",label='Prey')
plot2=plt.
,→plot(range(len(predatorCounts)),predatorCounts,"r",label='Predator')
plt.xlabel('Time in years')
plt.ylabel('Number of Prey/Predators')
plt.axis([0,50,0,2000])
2
legend=plt.legend()
plt.title('Predator and Prey Trends')
plt.show()
0.6 Submission
1. Remember to add the code below to the beginning of your assignemnet with today’s date and
your name and student ID
2. Follow the steps from the labs/how-to-submit.pdf file to submit your work.
Note. Instructions are updated to include both .ipynb and .pdf notebook versions.