Path: news.mathworks.com!not-for-mail
From: "Marios Karaoulis" <marios_hellas_23@yahoo.gr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: efficient programming
Date: Thu, 13 May 2010 21:48:04 +0000 (UTC)
Organization: Aristoteleio
Lines: 49
Message-ID: <hshs2k$eaq$1@fred.mathworks.com>
References: <80d20481-e56d-4835-a198-4c7d7f86384b@31g2000prc.googlegroups.com> <852a0217-6000-4eb7-8084-67dd877f3d1f@j36g2000prj.googlegroups.com> <hsa579$nbk$1@fred.mathworks.com>
Reply-To: "Marios Karaoulis" <marios_hellas_23@yahoo.gr>
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 1273787284 14682 172.30.248.38 (13 May 2010 21:48:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 May 2010 21:48:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 574495
Xref: news.mathworks.com comp.soft-sys.matlab:635621

How can i optimize this triple for loop?

num_mes=43;
num_param=104;
% pa and pm are a INTEGER matrices dimension 1Xnum_mes
pa=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9;];
pm=[3,4,5,6,7,4,5,6,7,8,1,5,6,7,8,9,1,2,6,7,8,9,1,2,3,7,8,9,2,3,4,8,9,3,4,5,9,4,5,6,5,6,7;];

% icon is a INTEGER matrix in 3X2470 dimensions
icon=randi([1 1303],3,2470);
%aaa is a float matrix with 10X1303 dimensions
aaa=rand([10,1303]);
%x_flux y_flux is a float matrix with 10X2470 dimensions
x_flux=rand([10,2470]);
y_flux=rand([10,2470]);

%width_param is a INTEGER mX1 matrix, that shows how many times the
%internal loop must be calculated.
width_param=randi([1 50],num_param,1);

for mes=1:num_mes
  for m=1:num_param
      for k=1:width_param(m)
         		 
                      l=param(m,k);
        			  a1=icon(1,l);     
                      a2=icon(2,l);
                      a3=icon(3,l);
                      area=area_elm(l);

			          i=pa(mes);
			          j=pm(mes);

			          s1=aaa(i,a1)+aaa(i,a2)+aaa(i,a3);
			          s2=aaa(j,a1)+aaa(j,a2)+aaa(j,a3);
			          sum=2*(aaa(i,a1)*aaa(j,a1)+aaa(i,a2)*aaa(j,a2)+aaa(i,a3)*aaa(j,a3))+s1*s2;
       
			          sum=area*sum*k_absc(kit)*k_absc(kit)/(12*prop(l)*prop(l));

			          jam=x_flux(i,l)*x_flux(j,l)+y_flux(i,l)*y_flux(j,l)+sum;

                      jactmp=jactmp+jam;
                
	     
      end
			 trans_jac2(mes,m)=jactmp;
     		 jactmp=0;
  end    
end