double and triple integral for a complex function. I coded but did not get any output
Show older comments
f = (-1) * (x + L/2) ./ ((x + L/2).^2 + (y - y1).^2 + (z - z1).^2).^(3/2);
The goal is to do the double integral of that function over dy1 and dz1 and then the next step is to do the triple integral of the result(double integration result) over dx,dy and dz. I tried these in several ways but it looks like Matlab is unable to to this integration. Any suggestion?
I just want to clarify again. The integration order can not be changed. The integration order should be dy1 dz1 and then dx dy dz. That means first I need to do the double integral (dy1 dz1) of that function and then I need to do the triple integral (dx dy dz) of that double integral result.
I have tried this in MATLAB by using integral2 and integral3 function but nothing works. The 5D integration needs to be solved numerically without changing the integration order.
I have tried this in mathmetica and found out the double integral (dy1 dz1) does not have any closed form solution.
My 3rd step is to try this 5D integral by using integral 2 and then cumetrapze for the triple integral. I can do the first double integral by integral2 function if I define x, y and z as matrix/vectors. I know the limits of x,y and z. So, I can make materices of x, y and z. Then integral2 will retun a results containing scaler numbers. But the problem is now, how I can do the triple integral of this results using cumtrapze. As my double integral answer only contains numbers. How I can convert this number in any form of equation and do the integral with respect to x, y and z. Do I need to write my own integration routine?
Any idea or suggestions?
The limits:
this is for rectangular material layers. here x = length =L = 12e-3, y = width = 3.8 e-3 and z = thickness = tm = 250e-6
y1 = width = 3.8e-3, z1 = thickness of another material layer = tf = 23e-6
then the limit should be y1_max = width/2, y1_min = -width/2, z1_max = tf/2, z1_min = -tf/2,
x_max = length/2, x_min = -length/2, y_max = width/2, y_min = -width/2, z_max = tm/2, z_min = -tm/2
5 Comments
David Goodmanson
on 31 Jul 2024
Edited: David Goodmanson
on 31 Jul 2024
Hi Orpita, what is the region of integration?
ORPITA SAHA
on 31 Jul 2024
Walter Roberson
on 31 Jul 2024
In theory,
syms x y y1 z z1
syms xl xu yl yu y1l y1u zl zu z1l z1u
f = (-1) * (x + 1/2) ./ ((x + 1/2).^2 + (y - y1).^2 + (z - z1).^2).^(3/2);
step1 = int(f, y1, y1l, y1u, hold=true)
step2 = int(step1, z1, z1l, z1u, hold=true)
step3 = int(step2, x, xl, xu, hold=true)
step4 = int(step3, y, yl, yu, hold=true)
step5 = int(step4, z, zl, zu, hold=true)
result = release(step5)
In reality, this takes a long time.
ORPITA SAHA
on 1 Aug 2024
Accepted Answer
More Answers (2)
David Goodmanson
on 2 Aug 2024
Edited: David Goodmanson
on 2 Aug 2024
Hi Orpita,
Here is a way to at least reduce the dimension of the integral from 5d to 3d. First of all, the quantity (x+1/2) seems like an unusual choice since the interval of integration for x is only
(-1/2)*12e-3 <= x <= (1/2)*12e-3
It's good if it is 1/2 though since that way the integrand can never have any near-singularities due to a tiny denominator. Here I will just use x0, x0 = 1/2 in this case, and also use xa and xb as the min and max limits for the x integration and similarly with ya,yb etc. for the others.
To cut to the chase, the 3d integral is
Int g(y1,z,z1) dy1 dz dz1 (2)
where
g(y1,z,z1) = asinh((yb-y1)/Ab) -asinh((ya-y1)/Ab) -asinh((yb-y1)/Aa) + asinh((ya-y1)/Aa)
and
Ab = ( (xb+x0).^2 + (z-z1).^2 )^(1/2)
Aa = ( (xa+x0).^2 + (z-z1).^2 )^(1/2)
Boring details: The initial integral is
Int (-1) * (x+x0)./( (x+x0).^2 + (y-y1).^2 + (z-z1).^2 ).^(3/2) dx dy dy1 dz dz1
The integrand is a perfect differential in x so we can immediately do the x integration to obtain the 4d integral
Int [ 1/ ((xb+x0).^2 + (y-y1).^2 + (z-z1).^2).^(1/2) ...
-1/ ((xa+x0).^2 + (y-y1).^2 + (z-z1).^2).^(1/2) ] dy dy1 dz dz1 (1)
Two basically identical integrands here. Consider the top one, and one can choose which variable to integrate next. Lets say y. Denote
Ab^2 = (xb+x0).^2 + (z-z1).^2
and make the substitution
(y-y1) = Ab sinh(u) d(y-y1) = Ab cosh(u) du % here y1 is treated as a constant.
Plug that in, obtain
Int Ab cosh(u) du / (Ab^2 + Ab^2 sinh^2(u))^(1/2) = Int Abcosh(u)/Abcosh(u)du = u
% and still dy1 dz dz1
now u = asinh( (y-y1) /Ab) and this is evaluated at the limits of y to obtain
asinh((yb-y1)/Ab) - asinh((ya-y1)/Ab)
This goes the same for the lower integral in (1) so the final result is as shown in (2).
As a side note, it is not a good idea to have a variable called 'length' since that is the name of a Matlab function.
7 Comments
ORPITA SAHA
on 2 Aug 2024
Edited: ORPITA SAHA
on 2 Aug 2024
x0 can also be set to L/2 instead of 1/2. So as far as I can see, @David Goodmanson 's analysis is still valid.
@David Goodmanson 's analysis leaves you with a 3d-integral over dy1 dz dz1 that you could try to evaluate using "integral3".
ORPITA SAHA
on 2 Aug 2024
David Goodmanson
on 3 Aug 2024
Edited: David Goodmanson
on 23 Aug 2024
Hi Orpita,
I should have spotted the small l, but for unclear-font reasons like this, I myself never use a variable called small l, and usually (unless it's clear from the context) any variable name that includes a small l. Notice how in this very message with its sans serif type, you can't tell the difference at all berween small l and capital I.
It appears that you have
X = (x+L/2) with -L/2 <= x <= L/2
so it's possible for X to take on the value 0, is that correct? If so, then when y=y1 and z=z1 there is a singularity in
f = (-1) * (x+L/2) ./ ((x+L/2).^2 + (y-y1).^2 + (z-z1).^2).^(3/2);
due to a zero in the denominator. But it is not a strong singularity and the function otherwise is smooth and nonoscillatory so I like the idea of using cumtrapz in three dimensions, especially if you change the boundary conditions very slightly so that you can make the grid spacings for e.g. z and z1 to be noncommensurate, so that (z-z1) can't be zero on the grid.
If neither of your analytic integrals is done in x I think you are going to have a difficult time finding an analytic exppression for the integration of any two of y,y1,z,z1.
ORPITA SAHA
on 16 Aug 2024
Walter Roberson
on 16 Aug 2024
By one of the fundamental theorems of integration, the order of integration does not matter, except for cases where the limits depend upon one of the variables being integrated over.
If the function has a singularity, you cannot integrate it, unless you are working with something like the Cauchy Principle Value
ORPITA SAHA
on 22 Aug 2024
ORPITA SAHA
on 23 Aug 2024
0 votes
12 Comments
Walter Roberson
on 23 Aug 2024
Your integrals all have constant bounds. According to basic theorems https://en.wikipedia.org/wiki/Order_of_integration_(calculus)#Basic_theorems the order of integration is irrelevant, provided that the functions are continuous and integrable.
Because, without changing the order, the integral does not have any closed form solution.
The int() function essentially performs pattern matching to try to determine analytic integrals. Sometimes, integrating by one variable first does not happen to match any of the stored patterns, but integrating by a different variable does happen to match one of the stored patterns. Therefore, int() over one variable might fail to find an analytic solution whereas int() over a different variable might find an analytic solution. This does not mean that the function has no analytic integral if done in one order instead of the other: it merely means that int() was not powerful enough to find the analyatic integral.
ORPITA SAHA
on 23 Aug 2024
I didn't spend time checking if your 5d integral exists. But if you want to try what you outlined above, I suggest the following loop. But you will have to check whether the final result stabilizes for different values of nx, ny and nz.
xmin = -length/2;
xmax = length/2;
ymin = -width/2;
ymax = width/2;
zmin = -tm/2;
zmax = tm/2;
nx = 10; % Number of intervals in x-direction
ny = 10; % Number of intervals in y-direction
nz = 10; % Number of intervals in z-direction
dx = (xmax-xmin)/nx; % Spacing in x-direction
dy = (ymax-ymin)/ny; % Spacing in y-direction
dz = (zmax-zmin)/nz; % Spacing in z-direction
for ix = 1:nx
xmid = dx/2 + (ix-1)*dx;
for iy = 1:ny
ymid = dy/2 + (iy-1)*dy;
for iz = 1:nz
zmid = dz/2 + (iz-1)*dz;
% Compute 2d-integral over y1 and z1 in (xmid,ymid,zmid)
two_dimensional_integral(ix,iy,iz) = ...;
end
end
end
% Approximate 5d-integral
fifth_dimensional_integral = sum(two_dimensional_integral(:))*dx*dy*dz
Walter Roberson
on 23 Aug 2024
integral() over a singularity might return anything.
If you are after the Cauchy Principle Value, then you need to split the interval and add the results of separate integrations with the singularities at the endpoints.
Before starting any numerical computations, it must be established that the 5d - integral exists (despite the singularities). If the integral has a physical meaning, asking for advice in a physics forum or at least in a mathematics forum makes sense in my opinion.
ORPITA SAHA
on 23 Aug 2024
Torsten
on 23 Aug 2024
Is the integral evaluated in the journal ? Can you provide a link ?
ORPITA SAHA
on 23 Aug 2024
Paul
on 4 Sep 2024
From this comment: "Before starting any numerical computations, it must be established that the 5d - integral exists."
Can you expand on how one might establish the existence of the integral, or any integral in general, and if Matlab can be used in that process?
Torsten
on 4 Sep 2024
Can you expand on how one might establish the existence of the integral, or any integral in general, and if Matlab can be used in that process?
I don't think that MATLAB can be used for this.
Usually, theoretical results from Lebesgue integration theory are used to establish that functions are integrable, e.g. the Dominated Convergence Theorem:
But in the present case, I can't come up with a way to proof the existence of the 5-fold integral. According to the publications in this field, it seems that it's obvious :-)
Walter Roberson
on 5 Sep 2024
integral() over a singularity might return anything
If you are using the integral*() family of functions, you must split the calculations at the boundary conditions.
My recollection of the basics is that, for the 1D case, a sufficient condition for the integral to exist is the limits of integration (a and b) are finite and the integrand f(x) is continuous on the closed interval [a,b]. Now that I think of it, I'm not even sure if Matlab can be used to verifty that a function to be integrated, either with int or integral, is continuous. There might be easy cases on the symbolic side to show that f(x) is discontinuous (e.g., if f(x) includes a heaviside).
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!