Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d45g2000hsc.googlegroups.com!not-for-mail
From: Lee <kaloklee@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: computing sum of squared deviations without a for-loop
Date: Sun, 26 Oct 2008 07:08:37 -0700 (PDT)
Organization: http://groups.google.com
Lines: 21
Message-ID: <be6e1c36-aa98-427b-b1d6-8ac03cc0f4ef@d45g2000hsc.googlegroups.com>
NNTP-Posting-Host: 72.94.68.64
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1225030117 1133 127.0.0.1 (26 Oct 2008 14:08:37 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 26 Oct 2008 14:08:37 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d45g2000hsc.googlegroups.com; posting-host=72.94.68.64; 
	posting-account=RiKZewoAAADk3sKH6GMxQxSZTKkgAMWv
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; 
	.NET CLR 2.0.50727; .NET CLR 3.0.04506; FDM; Windows-Media-Player/10.00.00.3990),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:497300


Hi,

I need to compute a matrix, S.
S is a m by m matrix.  It is representing sum of squared deviations.

Currently, it is computed using a for-loop:

S=[];
      for i=1:N
          x=G(:,i)-g_bar;
          S=S+(x*x');
end

where the inputs are:
G is a m by N matrix.
G(:,i) is the ith column of G,
g_bar is a m by 1 vector.

If you write out this for-loop mathematically, you can see S is simply
the sum of squared deviations.  But is there a way to compute it from
the inputs without such a for-loop?