interpolate value of 3D points on a meshgrid with a CUSTOM FUNCTION
10 ビュー (過去 30 日間)
古いコメントを表示
% particle to mesh interpolation function (NOT ARBITRARY)
H = 3/pi/rCut^2;
u = @(r) H*(1-r/rCut).*(r.^2<=rCut^2);
for k = 1:length(ptcls.q)
r = sqrt((X - ptcls.x(1, k)).^2 + (Y - ptcls.x(2, k)).^2 + (Z - ptcls.x(3, k)).^2);
rho_lr = rho_lr + ptcls.q(k)*u(r);
end
I want to speed up this simple loop where ptcls.q is the value I want to interpolate, X,Y,Z are the points of a meshgrid and ptcls.x is the 3D scattered position of particles inside the mesh. I cannot use scatteredInterpolant function since is slow and does not fit the math behind the problem, any idea on how to speed up the calculation?
0 件のコメント
回答 (1 件)
Torsten
2024 年 6 月 1 日
移動済み: Torsten
2024 年 6 月 1 日
I don't understand why you use ptcls.q on the right-hand side of an equation (thus as known) if you want to interpolate it.
Assuming ptcls.q is a row vector, the loop can easily be replaced by
r = sqrt((X - ptcls.x(1, :)).^2 + (Y - ptcls.x(2, :)).^2 + (Z - ptcls.x(3, :)).^2);
H = 3/pi/rCut^2;
u = H*(1-r/rCut).*(r.^2<=rCut^2);
rho_lr = sum(ptcls.q.*u)
6 件のコメント
Torsten
2024 年 6 月 1 日
Yes that's exactly what I sent, my question was if there is a smart way to select nodes of the mesh in order to reduce the numer of calculations with a matlab function
How should this be possible ? For each particle, you have to "order" the (X,Y,Z) coordinates with respect to their distance to the particle position in order to interpolate. And in order to achieve this, given a particle, you have to evaluate r for each triple (X,Y,Z).
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!