Incorrect Plot using Quiver

2 vues (au cours des 30 derniers jours)
Digvijay Rawat
Digvijay Rawat le 28 Mai 2016
Commenté : Star Strider le 28 Mai 2016
clear
close all
clc
x = -10:0.1:10;
y = -15:0.1:0;
for i = 1:length(y)
for j = 1:length(x)
if x(j)<-5 || x(j)>=5
A = 10;
gradA = 0;
if y(i)<-10
u(i,j) = 0;
v(i,j) = 0;
else
u(i,j) = 200/A;
v(i,j) = (200/(A*A))*gradA*y(i);
end
elseif x(j)>=-5 && x(j)<0
A = 5-x(j);
gradA = -1;
if y(i)-x(j)+5>=0
u(i,j) = 200/A;
v(i,j) = (200/(A*A))*gradA*y(i);
else
u(i,j) = 0;
v(i,j) = 0;
end
else
A = 5+x(j);
gradA = 1;
if y(i)+x(j)+5>=0
u(i,j) = 200/A;
v(i,j) = (200/(A*A))*gradA*y(i);
else
u(i,j) = 0;
v(i,j) = 0;
end
end
end
end
quiver(x,y,u,v);
xlabel('X');
ylabel('Y');
title('Vector plot of velocity field');
axis tight
grid on
Hi.
I am trying to run the above piece of code. It gives the quiver plot of the fluid velocity. Anyways, some of the velocity vectors are missing from the plot and I just cannot understand why. When you run the code, look for the vectors on the innermost side (the ones that make up the triangle edges). You will see that there are some vectors missing on the triangle edge. Can anyone explain why is this happening and where am I going wrong? I am attaching the image in case you are unable to run the code right now.
Thanks!
  1 commentaire
Star Strider
Star Strider le 28 Mai 2016
I can’t follow your code, so I’m entering this as a Comment rather than an Answer.
See if the meshgrid function can help with your fluid velocity calculations and gradient calculations later.
The meshgrid function and vectorised calculations (see the documentation for Array vs. Matrix Operations) are (in my experience, always) better than calculating your own matrices.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by