MATLAB: Time Complexity of Double Integration

double integration time complexity

I'm trying to run the following code as
clc
%--------Define Constants all are in MKS-------%
q=1.602e-19;
h=8.85e-12;
Eox=3.9*h;
Esi=11.8*h;
Ni=1.1e16;
Na=1e16;
Vgs=0.4;
L=36e-9;
tox=3e-9;
tsi=10e-9;
Vds=1;
Q=-q*Na;
V=Vgs;
t1=0.02586;%thermal voltage in V%
Vbi=0.56;%source side potential%
phi=0;
d1=0;
syms x y;
for n=1:1:20
kn=n*pi/L;
X1=((cosh(kn*(tox+tsi-y)))+(cosh(kn*(tox-y))))/(sinh(kn*tsi));
d2=L*(V*(1-(-1)^n))/((cosh(kn*tox))*pi*n);
d4=1/(kn*Esi*tanh(kn*tsi))+1/(kn*Esi*sinh(kn*tsi))+tanh(kn*tox)/(kn*Eox) ;
d3=Vbi*(1-(- 1)^n)/kn+(Vds*(-1)^(n+1))/kn+Q*(1-(-1)^n)/(Esi*kn*kn*kn);;
for m=1:1:10
k1=(2*m-1)*pi/(2*tox);
A1=V/k1+(sin(k1*tox)*(Vbi-Vgs))/(tox*k1^2);
A2=(V)/k1+(sin(k1*tox)*(Vbi+Vds-Vgs))/(tox*k1^2);
d1=d1+(2*(sin(k1*(tox)))*kn*(A1+A2*((-1)^(n+1)))/(tox*(kn^2+k1^2)));
end
Dsf=((d1+d2-d3))/d4;
phi=phi+2*((sin(kn*x))*X1*Dsf)/(kn*Esi*L);
d1=0;
end
phi1=phi+Vbi+(x/L)*Vds+(Q*(x*L-(power(x,2))))/(2*Esi);
integration=double(int(1/(int(exp((phi1)/t1),y,tox,tox+tsi)),x,0,L));
but this is taking too much time to simulate as n goes higher for n=10 it will take some minutes after that time increases so much here also I tried to analyze the terms in Dsf which have d1,d2 d3,d4 a file attached as constants2.pdf I hope this will help. this shows the how different terms converges w.r.t n and m
what I observed that m=10 would be enough but for n I have doubt
If this is possible then kindly tell how much minimum n requires? for get a good answer my meaning is answer should not be change at least one place after decimal for example for n=10 if answer is 1.56e-8 then for n=20 if answer is 1.5e-8 then this is okay
if any other way possible to evaluate the integration then that would be great which take less time and answer is also correct currently I'm using Matlab-2015 version

Best Answer

Unless you need a symbolic integral, the Symbolic Math Toolbox is not the preferred method. I would do the integration using the integral function twice, since you integrate ‘1/’ the result of the first integration.
Substitute your current ‘integration’ assignment with these three lines:
phi1_fcn = matlabFunction(phi1);
int_y = @(x) 1./integral(@(y) exp(phi1_fcn(x,y)./t1), tox,tox+tsi, 'Array',true);
integration = integral(int_y, 0,L)
This first creates anonymous function ‘phi1_fcn’ from ‘phi1’, then uses two calls to the integral function to integrate it. Using tic,toc, this takes a bit less that 700 milliseconds on my laptop. I get the same result for both my numeric integration and the symbolic integration.