Bellman equation with recursive function

조회 수: 9 (최근 30일)
Amit Kumar
Amit Kumar 2019년 1월 19일
답변: Amit Kumar 2019년 1월 23일
Hello,
I have a Bellman equation for which I have constructed a code with the help of loops, that calculates for me the optimal expected value:
function [V] = Bellmanneu(C,R1,R2,T,P1,P2,P0)
r = [R1 R2]
for t=(T+1):-1:1
for c=1:1:C+1
if c<=1
V(c,t) = 0
elseif t==T+1
V(c,t) = 0
else
V(c,t) = P1 * (r(1) + V(c-1,t+1)) + P2 * (r(2) + V(c-1,t+1)) + P0 * V(c,t+1)
end
end
end
end
Basically, I want to delete the first two for-loops and instead compute a recursive function that calls itself until t equals 1.
Can anyone help me out, at least with the first few steps that need to be taken?
Any help is much appreciated!
  댓글 수: 2
Star Strider
Star Strider 2019년 1월 19일
What are typical inputs to your function?
Amit Kumar
Amit Kumar 2019년 1월 19일
Hi, i`d like to keep it simple, so C=2, T=2 (important inputs),
P1=0.2, P2=0.6, P3=0.2, R1=50, R2=100.

댓글을 달려면 로그인하십시오.

답변 (1개)

Amit Kumar
Amit Kumar 2019년 1월 23일
With some help I could break down the whole function to the following:
function V = belmantest(C,R1,R2,T,P1,P2,P0)
V = zeros(C+1, T+1) % Pre-allocation!!!
for t = T:-1:1
V(2:C+1, t) = P1 * (R1 + V(1:C, t+1)) + P2 * (R2 + V(1:C,t+1)) + P0 * V(2:C+1, t+1)
end
end
Now, it is the last for-loop that I somehow need to get rid of.
Any suggestions?

카테고리

Help CenterFile Exchange에서 Automated Driving Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by