Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: matlab alternative to mtimesx for this problem ?
Date: Sun, 28 Aug 2011 18:58:10 +0000 (UTC)
Organization: University of Waterloo
Lines: 19
Message-ID: <j3e342$dbb$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1314557890 13675 172.30.248.48 (28 Aug 2011 18:58:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 28 Aug 2011 18:58:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1646679
Xref: news.mathworks.com comp.soft-sys.matlab:741504

Hello,

I want to integrate a function of w and t, wrt w, so the final answer should be a function of t. 

Rather than integrating wrt w, for each t in a loop, I tried three 'vectorized' ways:

w=0:0.0001:1;t=0:0.0002:2;
tic;a=trapz(w,repmat(w,length(t),1).*repmat(t',1,length(w)),2);toc;
tic;b=trapz(w,bsxfun(@times,w,t'),2);toc;
tic;c=trapz(w,mtimesx(w,'T',t),2);toc;
isequal(a,b) % 1
isequal(a,c) % 1

The first two take up 4GB of RAM while computing, and take more than 50 seconds.
The third method takes negligible RAM and only 0.003245 seconds.

I only recently learned about James Tursa's (amazing) NTIMESX (thanks to Bruno and Matt) , and I happened to learn about it due to a completely unrelated reason to this problem .... this result explained above seems almost too good to be true ! 

Assuming that what I am doing with MTIMESX here is actually giving the answer I want (and this seems true since ISEQUAL gave me 1) , is there a better MATLAB way to do this ? The reason why I'm asking is because I'm actually writing this code for a different group and I'm not sure if they have MTIMESX or even a C compiler.