0

I am trying to use a 100-point-grid to solve a dynamic programming system, but my array is not changing with each iteration--what am I doing wrong?

Thanks!

k_cur<-2
iterations<-100
A<- 4
alpha<-0.3
beta<-0.98
karray<-c(log(A*k_cur^alpha-(alpha*beta*A*(k_cur)^(alpha))))
awesomefunction<-function(iterations){
    for(i in 1:iterations){
          k_prime<-(alpha*beta*A*(k_cur)^(alpha))
          v_cur<-(log(A*k_curr^alpha-k_prime))
          karray<-append(v_cur,karray)
          k_cur<-k_prime
                          }
    print(karray)
    plot(karray)
  }
1
  • Why do you think your array is not changing with each iteration? Commented May 19, 2014 at 23:23

1 Answer 1

1

The only thing I can see is that k_cur is misspelled on line 11. The following ran for me:

k_cur<-2
iterations<-100
A<- 4
alpha<-0.3
beta<-0.98
karray<-c(log(A*k_cur^alpha-(alpha*beta*A*(k_cur)^(alpha))))
awesomefunction<-function(iterations){
    for(i in 1:iterations){
          k_prime<-(alpha*beta*A*(k_cur)^(alpha))
          v_cur<-(log(A*k_cur^alpha-k_prime))
          karray<-append(v_cur,karray)
          k_cur<-k_prime
                          }
    print(karray)
    plot(karray)
  }

awesomefunction(4)

and produced: output

Is that what you were after?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.