Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Minor disappointment with Matlab
Date: Tue, 8 Sep 2009 15:07:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 25
Message-ID: <h85rum$p3t$1@fred.mathworks.com>
References: <25f0b0e8-fa6b-4283-81eb-d3bfebeb4a97@c37g2000yqi.googlegroups.com> <37a033b3-1375-4593-b673-460ea2713401@x37g2000yqj.googlegroups.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1252422422 25725 172.30.248.38 (8 Sep 2009 15:07:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 8 Sep 2009 15:07:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:568998


Where do you get the factor 30??? Here is my test result (2009B/Vista):

function testcross

n = 1e6;
A = rand(3,n);
B = rand(3,n);

tic
C = cross(A,B);
toc % Elapsed time is 0.173915 seconds.

tic
C = [ A(2,:).*B(3,:) - A(3,:).*B(2,:); 
     A(3,:).*B(1,:)-A(1,:).*B(3,:); 
     A(1,:).*B(2,:)-A(2,:).*B(1,:) ];
toc % Elapsed time is 0.168631 seconds.

%%%%%

If you look at the code of CROSS (it is *not* a built-in, there is a mfile-  type CROSS, then open it using right mouse button menu to open it), it does exactly the same calculation like your code plus few overheads.

The factor 30 comes only when you use CROSS inside the for loop, which is a bad way of using it.

Bruno