Triple intergral for the array valued function

25 views (last 30 days)
Rohan
Rohan on 12 Apr 2024 at 12:31
Edited: Torsten on 16 Apr 2024 at 18:09
Hello,
I would like to perform triple intergral for my array valued function. The example of kind is below :
Generally, the command quadv works for the single variable integral. However, the integral3 or triplequad could not handle this. It throws the error. Example code below which throwing an Error. From my understanding, the integral3 can not handle array valued function. What would be the alternative way to handle this kind of situation
N1 =@(x,y,z) x.^2+y.^2+z.^2;
N2 =@(x,y,z) x.^2+y.^2+z.^2;
N3 =@(x,y,z) x.^2+y.^2+z.^2;
N4 =@(x,y,z) x.^2+y.^2+z.^2;
A =@(x,y,z)[N1(x,y,z), N2(x,y,z); N3(x,y,z), N4(x,y,z)];
integral3(A,0,2,0,2,0,2)
Error using integral2Calc>tensor (line 253)
Integrand output size does not match the input size.

Error in integral2Calc>integral2t (line 55)
[Qsub,esub,FIRSTFUNEVAL,NFE] = 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 334)
fx = FUN(t);

Error in integralCalc>vadapt (line 148)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, ...

Error in integralCalc (line 77)
[q,errbnd] = vadapt(vfunAB,interval, ...

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

Answers (2)

Ayush Anand
Ayush Anand on 12 Apr 2024 at 13:03
Hi,
You need to integrate each component of your array-valued function separately and then combine the results. You can call "integral3" multiple times to do this, once for each element in your array:
% Define N1,N2,N3,N4
N1 =@(x,y,z) x.^2+y.^2+z.^2;
N2 =@(x,y,z) x.^2+y.^2+z.^2;
N3 =@(x,y,z) x.^2+y.^2+z.^2;
N4 =@(x,y,z) x.^2+y.^2+z.^2;
% Integrate each component separately
I1 = integral3(N1, 0, 2, 0, 2, 0, 2);
I2 = integral3(N2, 0, 2, 0, 2, 0, 2);
I3 = integral3(N3, 0, 2, 0, 2, 0, 2);
I4 = integral3(N4, 0, 2, 0, 2, 0, 2);
% Combine the results into an array
A = [I1, I2; I3, I4];
Hope this helps!
  1 Comment
Rohan
Rohan on 12 Apr 2024 at 17:19
Hi, Thanks for the answer. Howeverm this is what i want to avoid.Because here above is just example. However, the real one looks more complicated and bigger. i would like to solve in one shot, with intrinsic function or in worst case looping.

Sign in to comment.


Torsten
Torsten on 12 Apr 2024 at 17:24
Edited: Torsten on 12 Apr 2024 at 17:36
N = cell(2,3);
N{1,1} =@(x,y,z) x.^2+y.^2+z.^2;
N{1,2} =@(x,y,z) x.^2+y.^2+z.^2;
N{1,3} =@(x,y,z) x.^2;
N{2,1} =@(x,y,z) y.^2+z.^2;
N{2,2} =@(x,y,z) x.^2+y.^2+z.^2;
N{2,3} =@(x,y,z) z.^2;
[I,J] = meshgrid(1:2,1:3);
A = arrayfun(@(i,j)integral3(N{i,j},0,2,0,2,0,2),I,J).'
A = 2x3
32.0000 32.0000 10.6667 21.3333 32.0000 10.6667
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  2 Comments
Rohan
Rohan on 16 Apr 2024 at 14:29
Really thanks for the answer. Does that also work with array valued function in form of matrices not cell array ? I tried some combination but failed.
Would you please provide variant for the matrices instead of cell array ? or it is not possible. I mean function handle in following kind.
N1 =@(x,y,z) x.^2+y.^2+z.^2;
N2 =@(x,y,z) x.^2+y.^2+z.^2;
N3 =@(x,y,z) x.^2+y.^2+z.^2;
N4 =@(x,y,z) x.^2+y.^2+z.^2;
A =@(x,y,z)[N1(x,y,z), N2(x,y,z); N3(x,y,z), N4(x,y,z)];
Kind regards,
Rohan
Torsten
Torsten on 16 Apr 2024 at 15:52
Edited: Torsten on 16 Apr 2024 at 18:09
Does that also work with array valued function in form of matrices not cell array ?
No. Your A from above is not a matrix of 4 function handles, but 1 matrix-valued function handle. Thus the elements of the matrix are not function handles on their own and cannot be extracted as such for the 3d-integration. And integrating all matrix functions in one go is not possible with integral3.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!