Triple intergral for the array valued function
5 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(2 个)
Ayush Anand
2024-4-12
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!
Torsten
2024-4-12
编辑:Torsten
2024-4-12
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).'
2 个评论
Torsten
2024-4-16
编辑:Torsten
2024-4-16
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!