How to avoid multiple integration of the function and speed up calculations?

2 次查看(过去 30 天)
Hello. I'm dealing with with the code, where I have to integrate complicated function S(q,k) over q. Then I have to make summation over the integer m from zero to m=100 and finally I have to perform integration over k. Until the final integration over k the code's execution takes about 4 minutes on my laptop. The main problem is very long integration procedure over k, about 6 hours! I understand the slow work is caused by the length of the vector R, which has 1001 elements and this produces 1001 times of integration of the function R(k). But I can't modify my code in a proper way in order to avoid this multiple integration and significantly speed up calculation. I will kindly appreciate for any help.
function z=test
tic
tt=-0.000689609;
t=0.242731;
muu=0.365908;
[m,NN]=meshgrid(0:100,-500:1:500);
fun1=@(a,q,N) a.*tanh((a.^2-muu)./(2*t)).*log((2*a.^2+2*a.*q+q.^2-2*muu-1i*2*pi*N*t)./(2*a.^2-2*a.*q+q.^2-2*muu-1i*2*pi*N*t))./q-2;
Gamma_0=@(q,N) tt*pi+integral(@(a)fun1(a,q,N),0,10000,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
y1= @(N,q,k) t*q./k*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*N.*t-(2*m+1)*pi*t))./(-k.^2-2*k.*q-q.^2+muu+1i*(2*pi*N.*t-(2*m+1)*pi*t)))./Gamma_0(q,N);
R1=@(q,k) integral(@(N)y1(N,q,k),500,1000000,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true)+1.88*t*(1/2000)*sqrt(2)/(pi^(3/2)*(1i*t)^(3/2))*q.^2;%1.896
R11=@(q,k) integral(@(N)y1(N,q,k),-1000000,-500,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true)+conj(1.88*t*(1/2000)*sqrt(2)/(pi^(3/2)*(1i*t)^(3/2))*q.^2);
y2=@(q,k) t*q./k*log((-k.^2+2*k.*q-q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t))./(-k.^2-2*k.*q-q.^2+muu+1i*(2*pi*NN(:,1).*t-(2*m(1,:)+1)*pi*t)))./Gamma_0(q,NN(:,1));
R2=@(q,k) sum(y2(q,k));
S=@(q,k) R1(q,k)+R11(q,k)+R2(q,k);
Sigma=@(k) integral(@(q)S(q,k),0.001,10,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
R=@(k) 2*sum(exp(1i*(2*m(1,:)+1)*pi*t*10^(-11))./(1i*(2*m(1,:)+1)*pi*t-Sigma(k)),2);
Number=integral(@(k) R(k),0.001,5,'AbsTol',1e-6,'RelTol',1e-3,'ArrayValued',true);
Number(1,:)
toc
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Robust Control Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by