Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Identifying repeating pattern in a vector
Date: Tue, 3 Nov 2009 16:25:03 +0000 (UTC)
Organization: Xoran Technologies
Lines: 27
Message-ID: <hcplgv$hgd$1@fred.mathworks.com>
References: <e09c467a-b65f-4636-bb80-67ba02bff5da@d10g2000yqh.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257265503 17933 172.30.248.38 (3 Nov 2009 16:25:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Nov 2009 16:25:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:582080


Eyal <efleminge@gmail.com> wrote in message <e09c467a-b65f-4636-bb80-67ba02bff5da@d10g2000yqh.googlegroups.com>...
> Hi
> 
> I have a function running a loop where a value is added to a vector at
> each iteration. So, for example, if the vector is x, it could look
> like:
> 
> Iteration 1: x=[1]
> Iteration 2: x=[1,3]
> Iteration 3: x=[1,3,2]
> Iteration 4: x=[1,3,2,6]
> Iteration 5: x=[1,3,2,6,2]
> Iteration 6: x=[1,3,2,6,2,6]
> Iteration 7: x=[1,3,2,6,2,6,2]
> 
> and so on.
> 
> As can be seen in the example above, at some point a repeating pattern
> of values may appear in x; this indicates the function has entered an
> infinite loop. I would like to be able to catch the pattern, say for
> example after 3 repeats. In the example above, that would be when the
> last 6 values of x are [2,6,2,6,2,6]; however, I do not know the
> values in advance, nor do I know the length of the repeating pattern
> (e.g. it could be [2,4,6,3,2,4,6,3,2,4,6,3]), though for practical
> purposes three values should be sufficient to catch this error.

It might be worthwhile explaining the process that generates x. It's obviously some kind of Markov process if 3 repititions is a certain indicator of an infinite loop. That means there might be a simpler state vector to monitor than the whole history of the process.