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:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.