I need help with a Triple Integral
72 views (last 30 days)
Asvin Kumar on 1 Nov 2019
Try using the following code:
fun = @(x,y,z) y; % y is r
zmin = @(u,v) sqrt(2-(v.^2)/20)+12; % z
zmax = @(u,v) 17.5-((v.^2)/3);
xmin = 0; % theta
xmax = 2*pi;
ymin = 0; % r
ymax = 3.60767;
result = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax)
This code rearranges the order of integration. This is done to support the order of computation of limits in integral3 keeping in mind dependency among variables. The limits of integration of ’z’ are dependent on values of ‘r’ while the limits of integration of ‘r’ and ‘theta’ are independent.
The documentation at https://www.mathworks.com/help/matlab/ref/integral3.html#btbbw_k-1-fun explains how the limits are computed. The limits ymin and ymax are computed using x, which is ‘theta’ in this case, and the limits zmin and zmax are computed using x, y, which are ‘theta’ and ‘r’ in this case.
That is why the code given above passes arguments in the order: ‘theta’ , ‘r’ , ‘z’. Note also that the code can be modified to pass the arguments such that ‘r’ comes first followed by ‘z' and then ‘theta’. ‘fun’ would then need to be appropriately modified but that approach could also produce the desired output.
Additionally, refer to the example at https://www.mathworks.com/help/matlab/ref/integral3.html#btdgkz_ for better understanding.
There exists an alternate approach to compute the triple integral. It uses the Symbolic Math Toolbox. Code attached below for reference:
syms z x r
tmp = int(r,z,sqrt(2-(r.^2)/20)+12,17.5-((r.^2)/3));
tmp = int(tmp,x,0,2*pi);
tmp = int(tmp,r,0,3.60767);
val = vpa(tmp)
David Goodmanson on 21 Feb 2022
this is really just a 1d integral. Since nothing depends on theta, the theta integration instantly gives an overall factor of 2pi. Since nothing depends on z, the z integration just gives the value at the upper limit minus the value at the lower limit, or
17.5-((r.^2)/3) - (sqrt(2-(r.^2)/20)+12)
There is an extra factor of r in the integrand, so all this reduces to
f = @(r) ( 17.5-((r.^2)/3) - (sqrt(2-(r.^2)/20)+12) ).*r
I = 2*pi*integral(f,0,3.60767)
I = 83.3625