필터 지우기
필터 지우기

Loop in Value Iteration Unrecognized by MATLAB

조회 수: 1 (최근 30일)
Laura Freitas
Laura Freitas 2021년 10월 25일
댓글: Laura Freitas 2021년 10월 26일
I am trying to solve a value iteration problem. I have a matrix, EV, with two columns which must be estimated seperately. However, my loop doesn't work and doesn't allow me to iterate past the initial guess value. Basically, nothing past comand "while" works. MATLAB doesn't return an error or anything, it just doesn't do anything.
%Algorithm
EV0 = zeros(90,2); %Guess initial value of 0.
EV0_0 = EV0(:,1); %Column where i =0.
EV0_1 = EV0(:,2); %Column where i=1.
V = log(exp(u_0 + beta*EV0_0) + exp(u_1 + beta*EV0_1));
EV1_1 = P1*V;
EV1_0 = P0*V;
EV1 = [EV1_0 EV1_1];
while abs(EV1 - EV0) > 0.01 % continue to iterate until convergence is achieved
EV0 = EV1;
EV0_0 = EV0(:,1); %Column where i =0.
EV0_1 = EV0(:,2); %Column where i=1.
V = log(exp(u_0 + beta*EV0_0) + exp(u_1 + beta*EV0_1));
EV1_1 = P1*V;
EV1_0 = P0*V;
EV1 = [EV1_0 EV1_1];
end
Any help to understand how exactly I can get the loop to work would be greatly appreciated!
  댓글 수: 2
Jan
Jan 2021년 10월 25일
We cannot run your program without the values of P0 and P1, beta, u_0 and u_1.
Laura Freitas
Laura Freitas 2021년 10월 26일
That's alright, the issue has been resolved. Thank you for the attempt though!

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

채택된 답변

Laura Freitas
Laura Freitas 2021년 10월 26일
For clarification, EV1, EV0, P0 and P1 are matrixes, while u_0 and u_1 are vectors. EV1 and EV0 are 2x175, P0 and P1 are 175x175 and u_0 and u_1 are 175x1.
I figured out the issue myself. The issue was that EV1 and EV0 are matrixes. Hence,
abs(EV1 - EV0)
is also a matrix and does it makes no sense to compare it to a single number epsilon.
I fixed my code by setting:
V = max(max(abs(EV1 - EV0))); %The maximum difference between any two elements of EV1 and EV0
while V > epsilon
EV0 = EV1;
EV0_0 = EV0(:,1); %Column where i =0.
EV0_1 = EV0(:,2); %Column where i=1.
V = log(exp(u_0 + beta*EV0_0) + exp(u_1 + beta*EV0_1));
EV1_0 = P0*V;
EV1_1 = P1*V;
EV1 = [EV1_0 EV1_1];
V = max(max(abs(EV1 - EV0)));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by