Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stopping itteration

0 views
Skip to first unread message

Jehad Zughyer

unread,
Jul 20, 2008, 2:53:02 PM7/20/08
to
I am making this MDP value iteration algorithm and getting
stuck on how to stop it when the difference between the
last value and the older one is less than epsilon. Here is
the code:
%%%%%%%%%%%%%%%%%%
pij=[0.5 0.5 0; 0.5 0 0.5; 0 0.5 0.5];
ri=[4;0;-8];
VT=ri;

for n = 1:100
%%%%while (new VT-old VT)>=0.005 (how do I make this??)
s=1:3;
k=1:3;

discountedsum =pij(s,k) * VT(k);
VT=ri(s)+ 0.5*(discountedsum)

%%%end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Matt Fig

unread,
Jul 20, 2008, 3:21:02 PM7/20/08
to
Here is an example of how to do this kind of thing. The cnt
simply lets you know how many times the loop iterated.


VT1 = 20;
VT2 = 1;
cnt = 0;

while abs(VT2-VT1)>=0.005
VT2 = VT1;
VT1 = VT1/2;
cnt = cnt + 1;
end
cnt


You will have to modify this for your application because
your VT is an array, not a scalar. For example:

if ([2 3]>[1 5]),disp('inside the if'),end
if ([2 3]>[1 0]),disp('inside the if'),end

0 new messages