-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpractice 6.2 pretest.Rmd
54 lines (48 loc) · 1.05 KB
/
practice 6.2 pretest.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "practice 6.2 pretest"
output:
html_document: default
word_document: default
date: "2022-10-28"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, eval=F, include=T}
grow<-function(start_1, start_2){
num_gen<-30
N1 <- rep(0,num_gen)
N2 <- rep(0,num_gen)
generation<-1:num_gen
growth.rate<-1.2
K1<-100
K2<-120
a12<-0.8
a21<-0.8
N1[1]<-start_1
N2[1]<-start_2
for (i in 2:num_gen) {
N1[i] = N1[i-1] + (3.2* N1[i-1] * ((K1-N1[i-1]-(a12*N2[i-1]))/K1))
N2[i] = N2[i] + (growth.rate * N2[i-1] * ((K2-N2[i-1]-(a21*N1[i-1]))*K2))
#generation[1]=1
print (N1[i])
}
if (N1[1]>2){
plot(N1~generation,typ="b",ylim=c(0,min(c(K1,K2))),ylab="N")
} else {
plot(N1~generation,typ="n",ylim=c(0,min(c(K1,K2))),ylab="N")
}
print(N2[1])
if (N2[1]>0){
lines(N2~generation,typ="b",col=2)}
}
grow(1,0);
grow(1,2)
par(mar=c(9,4,1,1),mfrow=c(5,1),las=1)
grow(1,0)
text(4,110,"Species 1 alone")
grow(0,1)
text(4,110,"Species 2 alone")
grow(1,2)
text(6,110,"Both Species competing")
```