Path: news.mathworks.com!not-for-mail
From: "James Wright" <jameswright1001@yahoo.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help speeding up/replacing loops
Date: Tue, 16 Jun 2009 23:57:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <h19bgd$r3j$1@fred.mathworks.com>
References: <h18ge7$gta$1@fred.mathworks.com> <h18lud$rpl$1@fred.mathworks.com> <h18p3l$3u1$1@fred.mathworks.com>
Reply-To: "James Wright" <jameswright1001@yahoo.co.uk>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245196621 27763 172.30.248.35 (16 Jun 2009 23:57:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 16 Jun 2009 23:57:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1878517
Xref: news.mathworks.com comp.soft-sys.matlab:548126


"Matt Fig" <spamanon@yahoo.com> wrote in message <h18p3l$3u1$1@fred.mathworks.com>...
> 
> 
> 
> P = cumsum(B(1:N).*cos((1:N)*C(f)));
> Q = cumsum(B(1:N).*sin((1:N)*C(f)));

Thank you so much, I'd been playing around with the cumsum trying to get it to work, but couldn't see how. Could you also help with vectorizing this?

for j = 1:N
    x = a*x*(1-x);
    B(j) = x;
    E = E + x;
end


Obviously I could rewrite this as,

B(1) = a*x*(1-x);
E = B(1);
for j = 2:N
     B(j) = a*(B(j-1))*(1-(B(j-1)));
     E = E + B(j);
end


But to vectorize it would I have to use the cumprod command?