Bellman equation with vector input

6 ビュー (過去 30 日間)
Amit Kumar
Amit Kumar 2018 年 12 月 17 日
回答済み: Jan 2018 年 12 月 18 日
Hello,
I am trying to solve a dynamic programming problem with the help of the Bellman equation and backward recursion (meaning that optimum value must be found backwards, starting at the end)
My code looks like this:
function [V] = Bellman(K,B,P,G,T)
C = [B K-B]
for t=(T+1):-1:1
for c=[1 1]:C
if t==T+1
V(c,t) = 0
else
V(c,t) = 0.5*max(V(c,t+1),P+V(c(1)-1,t+1)) + (t/(2*T))*max(V(c,t+1),G+V(c,t+1)) + 1-0.5-(t/(2*T))*V(c,t+1)
end
end
end
The value V should be calculated for each period t and for different capacity levels c. However each c consists of two elements (e.g.: c=[1 1]). Obviously, when I run my code, I get the error: Subscript indices must either be real positive integers or logicals, because either I have subscript indices of value 0 or my code isn't iterating over the vector c, whose element should increase by 1 seperatly (e.g. c=[1 1, 2 1, 2 2, 3 2, 3 3,...]).
I hope my problem is clear and someone can help me out.
Thanks !
  1 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 17 日
V(c(1)-1,t+1)) ==> c(1)=1 1-1 == 0 zero cannot be an index in matlab!!

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2018 年 12 月 18 日
Replace:
C = [B K-B];
for c=[1 1]:C
...
by
C = [B K-B];
for c1 = 1:B
for c2 = 1:K-B
c = [c1, c2]
...
end
end
But the problem remains:
V(c(1)-1,t+1))
Here c(1)-1 is 0, as madhan has mentioned already.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by