Question: What's wrong with my code? This last entry: for( i in 1:t) N[i + 1, ]

What's wrong with my code? This last entry: for( i in 1:t) N[i + 1, ] <- dlvcomp2(N[i, ], alphas) gives me the error message "Error in alphas[2, 1] : subscript out of bounds" ...what does this mean...how do I fix it? All i want to do is create a 40-year simulation.

I'm coding using R

dlvcomp2<-function(N,alphas,rd= c(1, 1 ), K= c(1000,1000)) { N1.t1 <-N[1]+rd[1] * N[1] * (1 -alphas[1,1]*N[1]-alphas[1,2]* N[2]/ K[1]) N2.t1 <- N[2] +rd[2]*N[2] * (1-alphas[2,1]*N[1]-alphas[2,2]*N[2]/K[2]) c(N1.t1,N2.t1) }

alphas<-matrix(c(0.7220 , 0.7245),ncol = 2, byrow = TRUE) rd<- c(0.6,0.3) k<-c(1000,1000) t<-40 N <- matrix(NA, nrow = t + 1, ncol = 2) N[1, ]<- c(60, 60) for( i in 1:t) N[i + 1, ] <- dlvcomp2(N[i, ], alphas)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!