Incorrect Plot using Quiver
2 views (last 30 days)
Show older comments
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 Comment
Star Strider
on 28 May 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.
Answers (0)
See Also
Categories
Find more on Vector Fields in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!