Matlab 对面积或体积上的不均匀采样函数进行数值积分

Matlab 对面积或体积上的不均匀采样函数进行数值积分,matlab,interpolation,numerical-methods,numerical-integration,Matlab,Interpolation,Numerical Methods,Numerical Integration,从一些有限元建模软件中,我得到了三维体积上某些函数的值。我想把这个函数的值积分到体积上。问题在于,从FEM软件导出的数据没有定义规则网格上的函数,而是定义了与FEM软件使用的(不均匀)网格相对应的点集合(x、y、z) 如何在Matlab中完成此集成?一种方法是将函数重新采样到常规网格上: % Suppose f gives values of the function at points (x,y,z) % Here we will resample f onto a regular grid.

从一些有限元建模软件中,我得到了三维体积上某些函数的值。我想把这个函数的值积分到体积上。问题在于,从FEM软件导出的数据没有定义规则网格上的函数,而是定义了与FEM软件使用的(不均匀)网格相对应的点集合(x、y、z)

如何在Matlab中完成此集成?

一种方法是将函数重新采样到常规网格上:

% Suppose f gives values of the function at points (x,y,z)
% Here we will resample f onto a regular grid.

% Define the x, y, and z axis vectors for the new grid.
xg = linspace(min(x), max(x), 100);
yg = linspace(min(y), max(y), 100);
zg = linspace(min(z), max(z), 100);

% Define the new grid
[Xg, Yg, Zg] = meshgrid(xg, yg, zg);

% Define an interpolator for the sampled function
F = TriScatteredInterp(x, y, z, f);
Fg = F(Xg, Yg, Zg);

% Now we have the function sampled on a regular grid and can use the
% traditional matlab techniques.

dx = xg(2) - xg(1);
dy = yg(2) - yg(1);
dz = zg(2) - zg(1);

my_integral = sum(sum(sum(Fg))) * dx*dy*dz;

但是有更好的方法吗?

这取决于您的数据结构,但是如果您有一个四面体网格和节点处给定的值,那么您处理的是分段线性函数,只需要使用中点规则:对于每个四面体,计算体积;计算四面体节点的平均值,将这两个节点乘以单个元素的积分,然后在整个网格上求和。