Integrate pressure over area, from dataset points

Hi, i want to compute the integral over the area of the pressure distribution p(x,y). I have vectors x and y ,say each one of size n by 1,containing the coordinates at which the pressure is known, and a vector of pressures, size n by 1, with the pressure at each coordinate. I thought i could use trapz 2 times to compute the integral first in one direction and then the other, but to do this i would need a Matrix of pressure, instead i have a vector of the same size of the coordinates x and y. I also know that the area I have is an anulus surface, as i can see from plotting using stem3(x,y,p). The coordinates are taken w.r.t the center of the anulus, in cartesian coordinates. Hope you can help me figure this out, thanks.

5 Comments

Well the basic mathematics is to multiply the pressure at a given radius with the area of ring corresponding to the given radius, and sum for all the values for radius values.
But this approach comes with a set of assumptions, that might not be valid for the data you have.
We will need the data you are working with to suggest a working solution.
Thank you for your answer. I leave attached the vectors of x,y and p. The x and y are the coordinates of the anular area and the p vector is the vector describing the function(pressure) value at each point. For some reason i cannot upload the actual case vectors, so these are vectors i created as an example, with the only difference in the p vector being random. Anyway, the problem description is still the same.
You most likely want to use scatteredInterpolant as @Torsten shows in his answer below (scroll down).
Why not just sum the discrete values of Pressure-force at each point?
Torsten
Torsten on 31 Oct 2023
Edited: Torsten on 31 Oct 2023
If your suggestion was used, the density of the measurement points had to mirror the areas associated with them. But imagine data accumulating in a certain area while in another, there are almost no measurements. In this case, the weights for the datapoints in the integration couldn't be equally chosen.

Sign in to comment.

 Accepted Answer

Maybe you want to get mean pressure over the face. In this case, divide "sol" by area = pi*(5^2-1^2) as done below.
x = load("x.mat")
x = struct with fields:
x1: [1323×1 double]
y = load("y.mat")
y = struct with fields:
y1: [1323×1 double]
p = load("p.mat")
p = struct with fields:
p: [1323×1 double]
plot(x.x1,y.y1,'o')
F = scatteredInterpolant(x.x1,y.y1,p.p);
fun = @(r,theta)F(r.*cos(theta),r.*sin(theta)).*r;
sol = integral2(fun,1,5,0,2*pi)
Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test.
sol = 37.9349
mean_sol = sol/(pi*(5^2-1^2))
mean_sol = 0.5031

5 Comments

Thank you for your answer Torsten. I tried the code but I noticed that with this method that the function fun shows values different from 0 in points where the pressure should be null, as in the center "hole", maybe it is due to the interpolation. Moreover if iI compare the values returned by the fun with the values of the original data, for example at some radius and theta=0 are easier to check, they are very different.
I don't have your data - so I cannot comment on this.
If you integrate from 1 to 5, interpolation of your data within the hole is irrelevant.
At the points where you supply your data for pressure, the interpolated values should be equal to the original values. What "scatteredInterpolant" makes in between depends on the noisiness of your data.
Even for the random values above, the integration with "scatteredInterpolant" is near to the expected. So I'm quite surprised that you get unexpected results.
Since your data are gridded, applying trapz two times should also work:
x = load("x.mat");
x = x.x1;
y = load("y.mat");
y = y.y1;
p = load("p.mat");
p = p.p;
plot(x,y,'o')
rho = sqrt(x.^2+y.^2);
theta = atan2(y,x);
theta = wrapTo2Pi(theta);
plot(rho,theta,'o')
rho = reshape(rho,21,[]);
theta = reshape(theta,21,[]);
p = reshape(p,21,[]);
I1 = trapz(theta(1,:),trapz(rho(:,1),p.*rho,1)) % integrate in rho-direction first
I1 = 37.1605
I1 = I1/(pi*(5^2-1^2))
I1 = 0.4929
I2 = trapz(rho(:,1),trapz(theta(1,:),p,2).*rho(:,1)) % integrate in theta-direction first
I2 = 37.1605
I2 = I2/(pi*(5^2-1^2))
I2 = 0.4929
Thank you for your answer Torsten, I'll try the code with my data, i want to ask you, why using reshape on the data and using 21, does it have any effect on computing the integral?
Study the example
Multiple Numerical Integrations
under
to learn about the necessary format of your function data in order to use "trapz" for a 2d integration.
If you have problems to make your data compatible with the required format for "trapz", use the "scatteredInterpolant" approach - the setup is easy and the results won't differ significantly in my opinion.
Thank you very much for the help Torsten, I'll have a better look at trapz.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!