Incorrect Plot using Quiver
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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 Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!