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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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