Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Contracting Matrices
Date: Sat, 27 Dec 2008 17:23:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <gj5o9m$n2n$1@fred.mathworks.com>
References: <gj5ksv$1mq$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1230398582 23639 172.30.248.38 (27 Dec 2008 17:23:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 27 Dec 2008 17:23:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:508902


"Philosophaie" <ertlejack@sbcglobal.net> wrote in message <gj5ksv$1mq$1@fred.mathworks.com>...
> I have a 4x4x4x4 matrices.  I want to contract one of the indices and make a 4x4x4 matrix.  The original matrix has both co and contra- varient components.  Here is a excerpt from my code:
> 
>     for j=1:4
>         for k=1:4
>            for i=1:4
>             Ricci(j,k)=Ricci(j,k)+Riemann(j,k,i,i)
>         end
>     end
> end

  Try:

 temp = reshape(Riemann,4,4,[],1);
 Ricci = squeeze(sum(temp(:,:,1:4+1:4*4,1),3));

However it produces a 4x4 size, not 4x4x4.

Roger Stafford