MATLAB: How to do numerical multiple integral (more than triple) by using matlab

numerical integration

Dear friends, my question is How to do numerical multiple integral (more than triple) by using matlab?
For example, I have a function,Y = Func. It has 5 var. Hence, Y= func(a,b,c,d,e). If I want to do the integration with respect to a,b,c,d,e. (var a is the first one, e is the last one.) And region of a = [0 ,b] (this is a function handle), b = [0,c], c= [0.d], d= [0,e], e=[0, Inf].
Now, here is my 'real' question. the code is below
%%%==== just some parameters ====
a=4;
la1=1/(pi*500^2); la2= la1*5;
p1=25; p2=p1/25;
sgma2=10^(-11);
index=1;
g=2./a;
syms r u1 u2 u3 u4 u5
index = -2;
powe= index ;
seta= 10^powe;
xNor = ( (u5./u1).^(a./2)+ (u5./u2).^(a./2) + (u5./u3).^(a./2)+ (u5./u4).^(a./2) + 1 ).^(2./a);
x = (xNor).^(0.5) * seta^(-1/a);
q=pi.*(la1.*p1.^(2./a)+la2.*p2.^(2./a));
%%%==== parameters end ====
fun1 = r./(1+ r.^a );
out1 = int(fun1, x, Inf) ;
out1fcn = matlabFunction(out1); %%===Convert symbolicto function handle
y = @(u5,u4,u3,u2,u1) exp(-u3.*(1+2.*... %%<== in method 3, replace as 'y= exp(-u3.*(1+2.*...'
( out1fcn )./... %%<== in method 3, replace as '( out1 )./...'
( (( (u5./u1).^(a./2)+ (u5./u2).^(a./2) + (u5./u3).^(a./2)+ (u5./u4).^(a./2) + 1 ).^(2./a)).*seta.^(-2./a)))).*...
exp(-sgma2.*q.^(-a./2).* seta.*u3.^(a./2)./...
((( (u5./u1).^(a./2)+ (u5./u2).^(a./2) + (u5./u3).^(a./2)+ (u5./u4).^(a./2) + 1 ).^(2./a)).^(a./2)) );
%%%=== method 1, not working ============ upper ,lower bound should be a number
% y1 = integral( y ,0,@(u2) u2);
% y2 = integral( y1 ,0,@(u3) u3);
% y3 = integral( y2 ,0,@(u4) u4);
% y4 = integral( y3 ,0, Inf);
%%%=== method 2, not working, y1 is already wrong ===============
%%%Undefined function 'minus' for input arguments of type 'function_handle'.
% y1 = quad( y ,0,@(u2) u2);
% y2 = quad( y1 ,0,@(u3) u3);
% y3 = quad( y2 ,0,@(u4) u4);
% y4 = quad( y3 ,0, Inf);
%%%=== method 3. not working, DOUBLE cannot convert the input expression into a double array. ==============
% y1 = int( y ,0,@(u2) u2);
% y2 = int( y1 ,0,@(u3) u3);
% y3 = int( y2 ,0,@(u4) u4);
% y4 = int( y3 ,0, Inf);
% y5 = double(y4)
Dear guys. could you copy the code to your matlab and take a look for me. Thank you so much for your time.
Thank you.

Best Answer

You can use INT if your problem can be handled symbolically. If not, numerical integration of a 5-fold integral in MATLAB requires nesting INTEGRAL, INTEGRAL2, and INTEGRAL3. I got tired of explaining how to do this, so I wrote integralN and put it on the file exchange.
There are some examples in the text at the top of the file. Basically, it's a straightforward extension of INTEGRAL2 and INTEGRAL3 in terms of how you call it.
You're going to have to reorder your variables because of the way your region is defined. By convention, the outermost integral is the first variable, and the innermost integral is the last. You need that reversed.
q = integeralN(@(e,d,c,b,a)fun(a,b,c,d,e),0,inf,0,@(e)e,0,@(e,d)d,0,@(e,d,c)c,0,@(e,d,c,b)b)