MATLAB: How to speed up calculations of integral and summation

numerical integrationspeedsum

Hello everybody
Regarding to my previous question I'd like to speed up calculations
function z=self_energy_summation
tic
ww=linspace(0,10,100);
for l=1:100
S(l)=integral(@(q)Gamma_0(q,ww(l)),0,10,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
end
plot(ww,S)
function y1=Gamma_0(q,w)
z2=load('Tc_Tmatrix_ordered.txt');
tt=z2(741,1);
T_c=z2(741,2);
mu=z2(741,3);
k=1;
N=-1000:1000;
nn=10^4;
fun1=@(a,q) a.*tanh((a.^2-mu)./(2*T_c)).*log((2*a.^2+2*a.*q+q.^2-2*mu-1i*2*pi*N*T_c)./(2*a.^2-2*a.*q+q.^2-2*mu-1i*2*pi*N*T_c))./q-2;
R= T_c*q./k.*log((-k.^2+2*k.*q-q.^2+mu+1i.*(2*pi*N*T_c-w))./(-k.^2-2*k.*q-q.^2+mu+1i.*(2*pi*N*T_c-w))).*1./((tt+integral(@(a)fun1(a,q),0,nn,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true)));
y1=sum(R);
end
Time = toc
end
On the first step I reduced the relative tolerance of integral calculations. But even on my computer with 24 Gb RAM and Intel I7 processor I can't finish these calculations during the 24 hours. My question: is it possible to improve the performance of this code and reduced the time?

Best Answer

It seems wasteful to do this
z2=load('Tc_Tmatrix_ordered.txt');
inside the function that you are integrating. Can't you load z2 just once inside self_energy_summation? The nest functions will have access to it.