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

23 次查看(过去 30 天)
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 个评论
Dyuman Joshi
Dyuman Joshi 2024-3-19
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.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2024-3-19
编辑:Torsten 2024-3-19
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 个评论
Mehdi Morshedi
Mehdi Morshedi 2024-3-21
编辑:Mehdi Morshedi 2024-3-21
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 ??!!
Torsten
Torsten 2024-3-21
编辑:Torsten 2024-3-21
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by