Bruno Bastos Gonçalves
2010-Jul-24 15:13 UTC
[R] Doubt about a population competition function
Hi,
I'm doing a function that describe two populations in competition.
that's the function that i wrote:
exclusao<-function(n10, n20, k1, k2, alfa, beta, t){
n1<-k1-(alfa*n20)
n2<-k2-(beta*n10)
if(t==0){plot(t, n10, type='b', xlim=range(c(1:t),c
(1:t)), ylim=range(n10, n20), xlab='tempo',
ylab='tamanho populacional')
points(t, n20, type='b', col="red")
points(t,n10,type="b", col="black")
legend("topleft", c("Pop1","Pop2"), cex=0.8, col=c
("black","red"), pch=21:21, lty=1:1);
}
if(t>0){
for (i in 1:t){
n1[i==1]<-n1
n2[i==1]<-n2
n1[i+1]<-k1-alfa*n2[i]
n2[i+1]<-k2-beta*n1[i]
if(n1[i]==0){n1[i:t]==0}
if(n2[i]==0){n2[i:t]==0}
}
plot(c(1:t), n1[1:t], type='b', xlim=range(c(1:t),c
(1:t)), ylim=range(n1[1:t], n2[1:t]), xlab='tempo',
ylab='tamanho populacional')
points(c(1:t), n2[1:t], type='b', col="red")
legend("topleft", c("Pop1","Pop2"), cex=0.8, col=c
("black","red"), pch=21:21, lty=1:1);
}}
Where n10: size population in time 0, n20: size population in time 0, k1:
carrying capacity of the population 1, k2: carrying capacity of the population
2, alfa: competition coefficient of population 2 in population 1, beta:
competition coefficient of population 1 in population 2, t: time.
and when some population becomes 0 (ZERO), i want that population still 0 (ZERO)
until the end of "t". i have tried to put "
if(n1[i]==0){n1[i:t]==0} if(n2[i]==0){n2[i:t]==0}" after
"n2[i+1]<-k2-beta*n1[i]" in the for function, but nothing happens.
What may i do ?
Thanks
Bruno
[[alternative HTML version deleted]]
Hi,
I'm doing a function that describe two populations in competition.
that's the function that i wrote:
exclusao<-function(n10, n20, k1, k2, alfa, beta, t){
n1<-k1-(alfa*n20)
n2<-k2-(beta*n10)
if(t==0){plot(t, n10, type='b', xlim=range(c(1:t),c
(1:t)), ylim=range(n10, n20), xlab='tempo',
ylab='tamanho populacional')
points(t, n20, type='b', col="red")
points(t,n10,type="b", col="black")
legend("topleft", c("Pop1","Pop2"), cex=0.8, col=c
("black","red"), pch=21:21, lty=1:1);
}
if(t>0){
for (i in 1:t){
n1[i==1]<-n1
n2[i==1]<-n2
n1[i+1]<-k1-alfa*n2[i]
n2[i+1]<-k2-beta*n1[i]
if(n1[i]==0){n1[i:t]==0}
if(n2[i]==0){n2[i:t]==0}
}
plot(c(1:t), n1[1:t], type='b', xlim=range(c(1:t),c
(1:t)), ylim=range(n1[1:t], n2[1:t]), xlab='tempo',
ylab='tamanho populacional')
points(c(1:t), n2[1:t], type='b', col="red")
legend("topleft", c("Pop1","Pop2"), cex=0.8, col=c
("black","red"), pch=21:21, lty=1:1);
}}
Where n10: size population in time 0, n20: size population in time 0, k1:
carrying capacity of the population 1, k2: carrying capacity of the population
2, alfa: competition coefficient of population 2 in population 1, beta:
competition coefficient of population 1 in population 2, t: time.
and when some population becomes 0 (ZERO), i want that population still 0 (ZERO)
until the end of "t". i have tried to put "
if(n1[i]==0){n1[i:t]==0} if(n2[i]==0){n2[i:t]==0}" after
"n2[i+1]<-k2-beta*n1[i]" in the for function, but nothing happens.
What may i do ?
Thanks
Bruno
[[alternative HTML version deleted]]
Possibly Parallel Threads
- Setting a contingency table
- After writing data in MMF using SEXP structure, can i reference in R?
- [LLVMdev] memory-to-memory instructions
- help needed with printing multiple arguments as vectors, not matrices
- How to display each symbol in a different color using plot with summary.formula.reverse