【发布时间】:2014-05-27 00:38:05
【问题描述】:
我正在尝试创建一个向量,该向量将保存向量 vprime 以供以后绘制,但它不会出现在我的本地环境中(它没有写入向量)。有什么想法吗??
谢谢!!
###同时绘制所有三个###
space<-seq(length=100, from=0, to=7.2) ##Create a sequence of 100 values ending at the point where value goes negative
A<- 4 #take a as given
alpha<-0.3 #take alpha as given
beta<-0.98 #take beta as given
vprime3 <- c(1:100) ##create a vector length 100 to be replaced later
t_vj3 <- c(1:100) ##create a vector length 100 to be replaced later
iterater<-function(space){ ##create a function to perform the iteration
for(i in 1:100){ ##create for loop for one of the state space (varying k+1)
for(j in 1:100){ ##create for loop for another axis of the state spcae (varying k)
if((A*(space[i]^alpha)-space[j])<0){ #plug in the law of motion
t_vj3[j]=-99 #and have a case for negative consumption so it does not take a negative log
}
else {
t_vj3[j+1] <- (log(A*(space[i]^alpha)-space[j])+ beta*t_vj3[j]) #have the law of motion for positive values
}
}
vprime3[i]<-max(t_vj3) #and create a vector of the maximum values, or the value functions
}
a4<-vprime3
plot(space,vprime3, type="p", xlab="State Space", ylab="Value") # and plot this graph
}
iterater(space) #call the function
【问题讨论】:
-
您必须退回它才能使用它。你为什么要打印 then
concatenate then store asa4? -
我也只尝试了 a4
-
而且我已经运行了,还是没有出现
标签: r for-loop vector definition