MATLAB: How to integrate discrete values over a surface

numerical integrationtrapz

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?

Best Answer

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: