Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
Stopping itteration

Subject: Stopping itteration

From: Jehad Zughyer

Date: 20 Jul, 2008 18:53:02

Message: 1 of 2

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];

 for n = 1:100
   %%%%while (new VT-old VT)>=0.005 (how do I make this??)
  discountedsum =pij(s,k) * VT(k);
   VT=ri(s)+ 0.5*(discountedsum)

Subject: Stopping itteration

From: Matt Fig

Date: 20 Jul, 2008 19:21:02

Message: 2 of 2

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;

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us