Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Speeding up sum of squares
Date: Tue, 6 May 2008 17:21:05 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 34
Message-ID: <fvq421$p13$1@fred.mathworks.com>
References: <fm012450tjat7jgv5hqhtiokid3ketdsgj@4ax.com> <fvq0qr$7tv$1@fred.mathworks.com> <1v2124dbkuukhhprui7a8ss4vhmtgn3jcg@4ax.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
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 1210094465 25635 172.30.248.38 (6 May 2008 17:21:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 May 2008 17:21:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:466967


richardstartz@comcast.net wrote in message 
<1v2124dbkuukhhprui7a8ss4vhmtgn3jcg@4ax.com>...

> Thank you, John.
> 
> I have real column vectors, so it looks like your last suggestion will
> speed things up my nearly an order of magnitude. That would be really
> great.
> 
> If you have a minute, could you explain what it is that @() x'*x does
> and why it makes such a difference, or point me to the right stuff to
> read?
> 
> -Dick Startz
> 
> PS If it matters, I'm running 2007B on a dual processor Windows
> machine.
> 
> PPS What's timeit()?

timeit is a function from the file exchange,
written by Steve Eddins. Its a better way to
time code fragments than using tic and toc.

The product x'*x uses blas routines to speed
up the inner product. They are clearly much
more highly optimized than is the code
matlab produces for sum(x.^2). Bruno
pointed out that norm(x)^2 also is fairly fast.
I assume that it too is well optimized.

John