Error in function streamline: interp1 sample points must be unique.

91 vues (au cours des 30 derniers jours)
Leonardo Molino
Leonardo Molino le 7 Mar 2023
Hello everyone,
I have to display the streamlines of a supersonic flow around a cone. I have the meshgrid and the speed components in this fashion
x = [ 0, 0.333333333333333, 0.666666666666667, 1.00000000000000;...
0, 0.332271622840308, 0.664543245680615, 0.996814868520923;...
0, 0.331377263507562, 0.662754527015124, 0.994131790522686;...
0, 0.331191240165995, 0.662382480331990, 0.993573720497985];
y = [0, 0.0587561394208747, 0.117512278841749, 0.176268418262624;...
0, 0.0644900278013948, 0.128980055602790, 0.193470083404184;...
0, 0.0689384091852737, 0.137876818370547, 0.206815227555821;...
0, 0.0698266243496454, 0.139653248699291, 0.209479873048936];
Vx = 1.0e+03.* [ 2.9768 2.9856 2.9926 2.9941;...
2.9768 2.9856 2.9926 2.9941;...
2.9768 2.9856 2.9926 2.9941;...
2.9768 2.9856 2.9926 2.9941];
Vy = [524.7211 524.7211 524.7211 524.7211;...
477.1746 477.1746 477.1746 477.1746;...
442.4958 442.4958 442.4958 442.4958;...
435.4701 435.4701 435.4701 435.4701];
The quiver plot works nicely, but when I have to show streamlines I get this error
figure();
plot(x,y,'.k')
hold on;
streamline(x,y,Vx, Vy, zeros(1,4), zeros(1,4));
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in stream2 (line 63)
syi=interp1(yy(:),1:szu(1),sy(k));
Error in streamline (line 62)
verts = stream2(x,y,u,v,sx,sy,options);
Error in cuneo_vs_cono (line 65) (<--- this is the script name I am working on)
streamline(x,y,Vx, Vy, zeros(1,4), zeros(1,4));
I have attempted also with different starting points but I get always and always the same error. Maybe some errors in using them?
Thank you.

Réponses (2)

Benjamin Kraus
Benjamin Kraus le 7 Mar 2023
Modifié(e) : Benjamin Kraus le 7 Mar 2023
The issue you are having is the form of your X and Y data you are providing as input to streamline. The streamline doc page says (regarding the X input): "x-axis coordinates of vector data, specified as a 2-D or 3-D array that can be combined with Y (and optionally Z) to form a grid of coordinates. You can use the meshgrid function to create the arrays."
In this case, you have four values in your X and Y matrices that correspond to the same point (0,0), which is invalid input for streamline. The specific problem is that the first column of y is all the same. Those coordinates are being passed into interp1 and that is what is generating the error message.
X and Y are meant to reflect the coordinates of a grid of points, but the coordinates you provided are not really in a grid. Can you give more detail about what the values of X and Y mean in your data?
  1 commentaire
Leonardo Molino
Leonardo Molino le 7 Mar 2023
Modifié(e) : Leonardo Molino le 7 Mar 2023
Thank you for your answer.
The x and y coordinate data emerged from the conversion between spherical and linear coordinates. That is, I have solved the Taylor-Maccol problem in spherical coordinates. For each omega that represents an elevation with respect to the x-axis I have two velocity components, V_omega and V_r. Then, for each omega, I generated those points by converting the coordinates, giving a radius that goes from 0 to the tip of the cone
omega = flip(cell2mat({out(1).omega}.'));
Vr = flip(cell2mat({out(1).Vr}.'));
Vomega = flip(cell2mat({out(1).Vomega}.'));
npx = 80;
r = linspace(0,1/cosd(omega(1)),npx);
for k=1:length(omega)
for j=1:length(r)
x(k,j) = r(1,j).*cosd(omega(1,k));
y(k,j) = r(1,j).*sind(omega(1,k));
Vx(k,j) = Vr(k)*cosd(omega(k)) - Vomega(k)*sind(omega(k));
Vy(k,j) = Vr(k)*sind(omega(k)) + Vomega(k)*cosd(omega(k));
end
end
omega, Vr and Vomega come out from the ode45 solver. The points coincide at the very beginning of the matrices because they represents the origin of the cone.
Along a given elevation, the V_r and V_omega are the same for every given points. They change only when we "switch" from an elevation to another one.

Connectez-vous pour commenter.


David Wootton
David Wootton le 13 Fév 2024
Is there more on how to ovecome this error?
I'm having the same problem; I would like to show streamlines for ideal flow around a cylinder, so I'm also using a domain build from radial coordinates (using transfinite interpolation). I have tried just plotting the upper half-plane since it's symmetric, and there is no danger that the points are not unique.
If I plot contours of the streamfunction it works fine, but I would prefer to have arrows showing the flow direction, and to plot the streamlines over a different field (velocity magnitude or pressure coefficient) so would prefer to use streamslice or streamline, both of which crash out.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by