Incorrect Plot using Quiver

2 次查看(过去 30 天)
Digvijay Rawat
Digvijay Rawat 2016-5-28
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 个评论
Star Strider
Star Strider 2016-5-28
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by