从一些有限元建模软件中,我在三维体积上具有某种功能的价值。我想在卷上集成此函数的值。问题在于,从FEM软件导出的数据不会在常规网格上定义函数,而是在与FEM软件使用的(不均匀)网格对应的点(x,y,z)集合上。 p>
如何在Matlab中完成此集成?
答案 0 :(得分:2)
一种方法是使用TriScatteredInterp
将函数重新采样到常规网格上:
% 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;
但是有更好的方法吗?