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!
Are you trying something like this: