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

108 visualizaciones (últimos 30 días)
Subhankar
Subhankar el 20 de Nov. de 2024 a las 23:20
Comentada: Walter Roberson el 21 de Nov. de 2024 a las 19:13
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?

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Nov. de 2024 a las 0:32
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");
  4 comentarios
Subhankar
Subhankar el 21 de Nov. de 2024 a las 1:43
working now with scatterdataInterpolant. Thank you
Walter Roberson
Walter Roberson el 21 de Nov. de 2024 a las 19:13
I noticed that you marked that this solution did not work for you. Unfortunately you did not post any comments about what it is doing wrong for your purposes, so I do not know how to help you.

Iniciar sesión para comentar.

Categorías

Más información sobre Splines en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by