100 Point discrete grid in R

175 Views Asked by At

I am trying to use for loops to solve a 100 point discrete grid, but it is totally freaking out right now.

The code:

space<-c(1:100)
A<- 4
alpha<-0.3
beta<-0.98
vprime<-c(rep(0,100))
t_vj<-c(rep(0,100))
iterater<-function(space){
  for(i in space){
    for(j in space){
       t_vj[j+1] <- log(A*i^alpha-j)+ beta*tv_j[j] 
    }
    vprime[i]<-max(t_vj)
  }
plot(vprime)
}

Returns

 Error: object 'tv_j' not found

Why is this for loop not working? Thanks!

1

There are 1 best solutions below

0
On

Are you trying something like this:

space<-c(1:100)
A<- 4
alpha<-0.3
beta<-0.98
vprime<-c(rep(0,100))
t_vj<-c(rep(0,100))
t1 <- NULL
#iterater<-function(space){
for(i in space){
  for(j in space){
    t1[j] <- log(A*i^(alpha-j)) + beta*t_vj[j] 
  }
  vprime[i]<- max(t1)
}
plot(1:100, vprime)

plot