How to integrate discrete values over a surface

44 views (last 30 days)
I'm working on the outputs from a numerical model in which I've used a quadrangular mesh around a cylinder. Each element is defined by its coordinates (x, y) and the corresponding value of the parameter that I want to integrate so I have 3 different arrays containing these information.
My problem is related to the domain because I'm working with two circles, one inside the other (e.g. a plate with a hole) and the data related to the smaller one are NaN. I've tried to use trapz in order to get the difference between the two integrals but of course it didn't work. Is there any other way on how to do this?

Accepted Answer

John D'Errico
John D'Errico on 28 Dec 2019
Edited: John D'Errico on 28 Dec 2019
You are a bit ambiguous here, but I will guess I understand what you are asking.
You have a quad mesh over that domain. At each vertex of the mesh, you have a KNOWN value z(x,y).
Now you want to compute the two dimensional integral of z(x,y) over that domain? So the result will be a single scalar value. If this is your goal, then the answer is pretty simple.
  1. Reduce the quadrilateral mesh to a triangle mesh. That just requires you to arbitraily split each quad into a pair of triangles.
  2. The integral over that domain is easy, because the integral is just the sum of the integrals over each triangle.
  3. The integral over any triangle is easy, because it is just the sum of the z values at each vertex, multiplied by the area of the corresponding triangle, then dividing by 2.
In fact, you can do all of the above in not much more than one line, in a fully vectorized form. I'd probably take a few lines writing it to make it more readable of course.
What I don't know is if this is really your question. (It is often something completely different from what I might guess.) And I don't know for sure how your data is organized. So I won't write code unless I know what the problem really is. Otherwise, I might just be wasting my time.
It might help more to post your data (as a .mat file attachment to a comment.)
Of course, you could also write the solution in a slightly more complex way, working with the quad mesh itself. Then you need to integrate the unknown surface over each quad, then sum the results. Again, not that terribly difficult, IF this is really your goal.
The idea comes up in finite element methods, here is a start to read:
  5 Comments
Michael Obermeyer
Michael Obermeyer on 20 Aug 2020
Edited: Michael Obermeyer on 20 Aug 2020
Hi John, pretty late reply on this thread but I encountered a rather similar issue recently [z(x,y) known at the nodes]. A Gaussian quadrature as suggested by you or a mapping of the values to a uniform grid with a successive use of trapz [trapz(y,trapz(x,***))] seem to be the only two viable options.
Your comments on this seem to be correct at first glance except for
The integral over any triangle is easy, because it is just the sum of the z values at each vertex, multiplied by the area of the corresponding triangle, then dividing by 2.
Not being a mathematician but only an engineer, I cannot provide an off-the-shelf proof, but please consider the following:
  • Triangle {(0,0);(1,0);(1,1)}
  • Linear function z(x,y)=1-1*x
Analytical solution:
Your suggested solution:
Please right me if I'm wrong. And no offense - big shout-out for your outstandingly exhaustive answers!

Sign in to comment.

More Answers (2)

darova
darova on 28 Dec 2019
If your mesh if fine enough you can just multiply sides
123.png
(area of rectangle)
For better precision cross product can be used
  3 Comments
darova
darova on 28 Dec 2019
  • But that is just a complete conjecture at this point.
good
John D'Errico
John D'Errico on 29 Dec 2019
Edited: John D'Errico on 29 Dec 2019
Actually, I was kind of close, though the area of a quadrilateral does figure into the solution. They were not rectangles though.

Sign in to comment.


Deepanjan Das
Deepanjan Das on 13 Sep 2021
Hi, I am simulating a very simple 2d electrostatic model in Matlab. I have calculated the electric field over a rectangular surface. Now I want to evaluate. So I know the electric field value at each node but not the function. How can I do the integration? Please let me know. Thanks in advance.
  2 Comments
Deepanjan Das
Deepanjan Das on 13 Sep 2021
Edited: Deepanjan Das on 13 Sep 2021
No, it depends on the created mesh. Around the boundaries the elements are much smaller in size.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!