Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Double sum question
Date: Thu, 17 Jun 2010 03:05:09 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <hvc3d5$b7l$1@fred.mathworks.com>
References: <34f86e08-19ab-49a9-a3c0-e908bd93de65@j12g2000pri.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1276743909 11509 172.30.248.38 (17 Jun 2010 03:05:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 17 Jun 2010 03:05:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:645633

Marios Karaoulis <marios.karaoulis@gmail.com> wrote in message <34f86e08-19ab-49a9-a3c0-e908bd93de65@j12g2000pri.googlegroups.com>...
> I can't find a quick way to execute the following double sum.
> 
> i=integer
> j=integer
> b_node 3x1 vector
> c_node 3x1 vector
> 
> 
> %  sum
> x_flux1=((a(i,a1)*b_node(1)+a(i,a2)*b_node(2)+a(i,a3)*b_node(3)));
> x_flux2=((a(j,a1)*b_node(1)+a(j,a2)*b_node(2)+a(j,a3)*b_node(3)));
> 
> y_flux1=((a(i,a1)*c_node(1)+a(i,a2)*c_node(2)+a(i,a3)*c_node(3)));
> y_flux2=((a(j,a1)*c_node(1)+a(j,a2)*c_node(2)+a(j,a3)*c_node(3)));
> 
> 
> jam2=x_flux1*x_flux2+y_flux1*y_flux2;
> 
> 
> i tried this
> tmp_a(1)=a(i,a1);
> tmp_a(2)=a(i,a2);
> tmp_a(3)=a(i,a3);
> 
> tmp_b(1)=a(i,a1);
> tmp_b(3)=a(i,a2);
> tmp_b(3)=a(i,a3);
> 
> stable=((b_node*b_node'+c_node*c_node');
> a_11=sum ( sum( stable .* (tmp_a*tmp_b' ) ) );
> 
> but the results are not the same.
> Where is the error?

  If tmp_a and tmp_b are row vectors, the product tmp_a*tmp_b' will be a scalar which is definitely not what you want!  Do an initial allocation of them as column vectors before entering data into them and see if that doesn't improve things.

Roger Stafford