On R2018b and a new vanilla PC I found a significant decrease in computation time by replacing quad2d() by integral2() (with the same signature, i.e. defaults are used). With your input data this replacement didn't affect the result, out. (Caveat, I do this because I'm curious, not because I know much about the topic.) There are two posts on Double Integration in MATLAB ( and here ) at Loren on the Art of MATLAB. I don't find backing for the difference in speed that I've seen, which makes me a bit nervous. What's the catch? There ought to exist a discussion on how to chose between the two functions, but I fail to find it.
In response to comments
The difference in speed between integral2(), introduced in R2012a, and quad2d(), introduced in R2009a, that I see is irking.
I've compared your function, funct(), to funct_int2(), in which I replaced quad2d() by integral2(). (And split the long statement into three to make the code and the result of profile() easier to read.)
Elapsed time is 0.364935 seconds.
Elapsed time is 0.140186 seconds.
Elapsed time is 0.104307 seconds.
Elapsed time is 0.021930 seconds.
Elapsed time is 0.088423 seconds.
Elapsed time is 0.016356 seconds.
Elapsed time is 0.091209 seconds.
Elapsed time is 0.017180 seconds.
where cssm.m is a script containing
mu=1; lmax=4; wmax=6; hmax=30; lambdab=1; hu=40; hb=10; y=4; x=2;
for jj = 1 : 10
out1 = funct(mu,lmax,wmax,hmax,lambdab,hu,hb,y,x);
for jj = 1 : 10
out2 = funct_int2(mu,lmax,wmax,hmax,lambdab,hu,hb,y,x);
disp( out2-out1 )
function [out] = funct_int2(mu,lmax,wmax,hmax,lambdab,hu,hb,y,x)
f1 = lambdab.*y.*integral(S2,0,2*pi,'ArrayValued',true);
f2 = exp(-lambdab.*integral2(S1,0,y,0,2*pi));
f3 = (1-exp(-lambdab.*integral2(S1,0,1000,0,2*pi)));
out(ii) = f1.*f2./f3;
- Fine print; don't blame me for mistakes.
- In this comparison both integral2() and quad2d() use the "tiled method"
- The fact that the two return exactly the same result makes me believe that deep inside the same calculation is made.