Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorized function iterating
Date: Wed, 19 Mar 2008 08:37:02 +0000 (UTC)
Organization: Pieper GmbH
Lines: 39
Message-ID: <frqjbe$6n9$1@fred.mathworks.com>
References: <fro1g4$ibc$1@fred.mathworks.com> <fro48n$ljt$1@fred.mathworks.com> <frok2d$6os$1@fred.mathworks.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 1205915822 6889 172.30.248.38 (19 Mar 2008 08:37:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 19 Mar 2008 08:37:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 605234
Xref: news.mathworks.com comp.soft-sys.matlab:457992



"Ilya " <ilyapoz@gmail.com> wrote in message 
<frok2d$6os$1@fred.mathworks.com>...
> Yeah, ok, I get it )) Recursion rules, but I meant 
> without "for" not literally, I wanted to do this more 
> efficiently than with for.
> Moreover, f depends on x, not on i, so it's not 
recursive, 
> it's just describes a discrete time dynamic system x_
{k+1} 
> = f(x_k).
> Any ideas?

If you know the number of time steps in advance, you can 
pre-allocate x.

 x = zeros(N, 1);

 x(1) = start_value; % not necessary if x(1) == 0

 for n = 2 : N

  x(n) = f(x(n - 1));

 end;

If you don't know the number of time steps beforehand, x 
should be a cell array.

 x = {start_value};

 while signal_is_updated

  x{end + 1} = f(x{n}); 

 end;

x{k + 1} = f(x{k}) and x{k} is a scalar. It is not a whole 
vector, but only a component of it. Vectorization means 
treating a vector as a unit, i. e. not indexing it.