I want to draw pathline for two particle for a 2d problem

조회 수: 97 (최근 30일)
Subhankar
Subhankar 대략 18시간 전
댓글: Subhankar 대략 15시간 전
I have the results for the space and velocity variables xn, yn, un, vn all in 50*300*2085 dimensions. My space points xn,yn are changing with time along with un, vn. I tried to write the following
M = size(xn,1); N = size(xn,2); Nt = size(xn,3);
dt = 5*0.005; % need to be same as the data stored
% target point index
X0 = [0 0 ]; Y0 = [1.5 -1.5];
plot(X0,Y0,'r*','LineWidth',1); hold on;
for i = 1 : length(X0)
X(i) = X0(i); Y(i) = Y0(i);
for n = 1 : Nt
x = xn(:,:,n); y = yn(:,:,n);
u = un(:,:,n); v = vn(:,:,n);
F = griddedInterpolant(x,y,u,"spline","spline");
U = F(X(i),Y(i));
F1 = griddedInterpolant(x,y,v,'spline','spline');
V = F1(X(i),Y(i));
X(i) = X(i) + dt*U; Y(i) = Y(i) + dt*V;
XX(i,n) = X(i); YY(i,n) = Y(i);
end
end
plot(XX(i,:),YY(i,:),'b','LineWidth',1.2); hold on;
But end up with the error
'Error using griddedInterpolant
Grid arrays must have NDGRID structure.'
Can you please help me with this?

채택된 답변

Walter Roberson
Walter Roberson 대략 16시간 전
When you use griddedInterpolant, then your x must have all of its columns the same, and the row values must be sorted. Your y must have all of its rows the same and the column values must be sorted.
[X,Y] = ndgrid(1:3, 4:7)
X = 3×4
1 1 1 1 2 2 2 2 3 3 3 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y = 3×4
4 5 6 7 4 5 6 7 4 5 6 7
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Here, X and Y are valid for griddedInterpolant(X,Y,V)
X(2,2) = 2.01; X(2,3) = 2.02; X(2,4) = 2.03
X = 3×4
1.0000 1.0000 1.0000 1.0000 2.0000 2.0100 2.0200 2.0300 3.0000 3.0000 3.0000 3.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
This X is not valid for griddedInterpolant because the columns are not all the same as each other.
There is a different major sorting order,
[X2, Y2] = meshgrid(1:3, 4:7)
X2 = 4×3
1 2 3 1 2 3 1 2 3 1 2 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y2 = 4×3
4 4 4 5 5 5 6 6 6 7 7 7
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
For this arrangement, all of the rows of X2 are the same as each other and the columns are sorted.
These two orders are connected by
[Y3,X3] = meshgrid(4:7, 1:3);
X3, Y3
X3 = 3×4
1 1 1 1 2 2 2 2 3 3 3 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y3 = 3×4
4 5 6 7 4 5 6 7 4 5 6 7
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Anyhow, this "meshgrid" arrangement of data is not valid for griddedInterpolant.
Generally speaking, if you have meshgrid data, then you can
F = griddedInterpolant(x.',y.',u.',"spline","spline");
  댓글 수: 3
Walter Roberson
Walter Roberson 대략 15시간 전
F = scatteredInterpolant(xy, u, "linear", "linear");
would be more natural. On the other hand scatteredInterpolant does not handle spline.
Subhankar
Subhankar 대략 15시간 전
working now with scatterdataInterpolant. Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Splines에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by