MATLAB Integrating Trisurf for 3D Mesh Comparison in Domain D

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Integrating
AI Thread Summary
To compute the double integral of the squared difference between two 3D surfaces defined over the same domain using MATLAB, the process involves creating a mesh grid for the specified domain D = [0,2]×[0,2]. The surfaces, denoted as f1 and f2, can be represented as matrices of values. The integrand is calculated as (f1 - f2)^2. The integration is performed using the trapezoidal rule with the trapz function. First, integrate the values along the rows of the matrix, followed by integrating the resulting vector along the columns. An example illustrates this process, where f1 and f2 are defined as simple quadratic functions. The expected outcome serves as a sanity check for the implementation. If the initial data is coarse, interpolation can be applied to refine the mesh before performing the integration.
member 428835
Hi PF!

I have a 3D mesh generated via the trisurf function, where they each have different node numbers, but are both defined over the same domain ##D##. See attachments for clear image.

If the surfaces are ##f1## and ##f2##, I'd like to compute ##\iint_D(f1-f2)^2## where ##D = [0,2]\times[0,2]## . Any idea how?
 

Attachments

Physics news on Phys.org
Here is an example on how to do a double numerical integration:
http://www.mathworks.com/help/matlab/ref/trapz.html#buakefe-1_1

The idea is that you express the integrand as a matrix of values, then call trapz the first time operating on the rows, then take that result and integrate a second time operating on the columns. It looks something like this:

Code:
dx = 0.1;
dy = 0.1;
x = 0:dx:2;
y = 0:dy:2;
[X,Y] = meshgrid(x,y);   % create mesh
f1 = X.^2 + Y.^2;        % first surface defined on the mesh of (x,y) points
f2 = X.^2 + Y.^2 + 1;    % second surface
f = (f1 - f2).^2;        % integrand
Q = trapz(x,f,2);        % integrate wrt X
I = trapz(y,Q)           % integrate the result wrt Y

In this simple example you have the same surface separated vertically by 1 unit, so since the domain is a 2x2 square, you expect the integral to reproduce the volume of a 2x2x1 cube, which acts as a nice sanity check for the code above:

Code:
I =

    4

If the data you have for the surfaces is coarse, you can interpolate to define the surface on a finer mesh, then integrate the new surface.
 
Last edited:
Back
Top