matlab guide for Calculating 6 dimensional numerical integral Dosen't work

How should I calculate 6 dimentinal numerical integration in matlab? my first try failed as below code :
I Know this problem can be solved symbolicly. but i need to calculate integral of a very complicated 6-D integral. which its integrand has product term of bessel fuctions, sin functions and exponential functions. and this simple example will guide me to solve that question.
My code in based on guide for 4-D numercal integration in https://nl.mathworks.com/help/matlab/ref/integral3.html which matlab stated : "The integral quadrature functions in MATLAB® directly support 1-D, 2-D, and 3-D integrations. However, to solve 4-D and higher order integrals, you need to nest calls to the solvers."
but matlab guide dosen't work ??!!
f = @(x,y,u,t,v,r) x*y*u*t*v*r ;
xmin = 0 ;
xmax = 1 ;
ymin = 0 ;
ymax = @(x) x;
umin = 0 ;
umax = @(x,y) x+y;
tmin = 0;
tmax = @(x,y,u) x+y+u;
vmin = 0;
vmax = @(x,y,u,t) x+y+u+t;
rmin = 0;
rmax = @(x,y,u,t,v) x+y+u+t+v;
Q1 = @(x,y,u) integral3(@(t,v,r) f(x,y,u,t,v,r) ,tmin,tmax,vmin,vmax,rmin,rmax)
Q1 = function_handle with value:
@(x,y,u)integral3(@(t,v,r)f(x,y,u,t,v,r),tmin,tmax,vmin,vmax,rmin,rmax)
Q2 = integral3(@(x,y,u) Q1(x,y,u) ,xmin,xmax,ymin,ymax,umin,umax)
Error using integral3
Invalid argument at position 3. Value must be a floating-point array.

Error in solution>@(x,y,u)integral3(@(t,v,r)f(x,y,u,t,v,r),tmin,tmax,vmin,vmax,rmin,rmax) (line 14)
Q1 = @(x,y,u) integral3(@(t,v,r) f(x,y,u,t,v,r) ,tmin,tmax,vmin,vmax,rmin,rmax)

Error in solution>@(x,y,u)Q1(x,y,u) (line 15)
Q2 = integral3(@(x,y,u) Q1(x,y,u) ,xmin,xmax,ymin,ymax,umin,umax)

Error in integral3>@(y,z)fun(x(1)*ones(size(z)),y,z) (line 129)
@(y,z)fun(x(1)*ones(size(z)),y,z), ...

Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); NFE = NFE + 1;

Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);

Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);

Error in integral3>innerintegral (line 128)
Q1 = integral2Calc( ...

Error in integral3>@(x)innerintegral(x,fun,yminx,ymaxx,zminxy,zmaxxy,integral2options) (line 111)
f = @(x)innerintegral(x, fun, yminx, ymaxx, ...

Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);

Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral3 (line 113)
Q = integralCalc(f,xmin,xmax,integralOptions);

5 Comments

When using integral3, you need to provide atleast 1 set of limits as numbers.
Otherwise, you need to use symbolic integration (Note - requires Symbolic Math Toolbox).
So Is it impossible to calculate 6-Dimentinal Numerical integration with combination of matlab integral, integral2 and integral3 functions?
Matlab in https://nl.mathworks.com/help/matlab/ref/integral3.html suggests we can calculate 4-Dimentinal or more with combination of integral, integral2 and integral3. but It is dosen't work for my simple example?!
As I mentioned above - When using integral3, you need to provide atleast 1 set of limits as numbers.
And, the example you linked uses numerical limits, not function handles.
What exactly are you trying to do? It would be helpful if you could specify the objective and provide more information.

Sign in to comment.

 Accepted Answer

tmax in Q1 must be a scalar, not a function handle.
Try "integralN":
f = @(x,y,u,t,v,r) x.*y.*u.*t.*v.*r ;
xmin = 0 ;
xmax = 1 ;
ymin = 0 ;
ymax = @(x) x;
umin = 0 ;
umax = @(x,y) x+y;
tmin = 0;
tmax = @(x,y,u) x+y+u;
vmin = 0;
vmax = @(x,y,u,t) x+y+u+t;
rmin = 0;
rmax = @(x,y,u,t,v) x+y+u+t+v;
value = integralN(f,xmin,xmax,ymin,ymax,umin,umax,tmin,tmax,vmin,vmax,rmin,rmax,'AbsTol',1e-5,'RelTol',1e-3)

2 Comments

if the problem can be solved with matlab's integral , integral2 and integral3 functions. the results will be excelent.
Matlab suggest this way, and I expect the Matlab's stategy can be applied on this simple question. But How ??!!
Within integralN, the 6-fold integration is done by using MATLAB's integral2 three times.
But if think you can do better than Mike Hosea from the MATLAB staff (e.g. by using integral3 two times or something similar), you are invited.
I tried your example for the 5-fold problem, and the integral was solved quite fast (1.5 min) with Mike Hosea's code. But - as noted in the documentation to the code - 6-fold integrals can take much longer.

Sign in to comment.

More Answers (0)

Asked:

on 19 Mar 2024

Edited:

on 21 Mar 2024

Community Treasure Hunt

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

Start Hunting!