Velocity potential with quiver command

조회 수: 25 (최근 30일)
rafael
rafael 2020년 8월 4일
답변: KSSV 2020년 8월 4일
Hi everyone,
I am studying potential flows, i tried to use the quiver command to determine the velocity field. I took this code of a freestream velocity around a cylinder with a vortex. I have the streamfunction. My idea was to find the velocity components u and v with derivatives of Streamfunction with respect y and x, respectively.
nx = 100;
xmin = -3.5;
xmax = 1.5;
ny = 100;
ymin = -3.0;
ymax = 1.5;
[x, y] = meshgrid(linspace(xmin, xmax, nx), linspace(ymin, ymax, ny));
U0 = 5.0;
Gamma = 8*pi;
xGamma = -1.0;
yGamma = -1.0;
K = 5.0;
xK = -1.0;
yK = -1.0;
radius = inline('sqrt((x-x1).^2+(y-y1).^2)', 'x', 'y', 'x1', 'y1');
PsiK = K*sin(atan2(y-yK, x-xK))./radius(x, y, xK, yK);
PsiGamma = Gamma*log(radius(x, y, xGamma, yGamma))/2/pi;
StreamFunction = U0*y-PsiGamma-PsiK;
levmin = StreamFunction(1, nx);
levmax = StreamFunction(ny, nx/2);
levels = linspace(levmin, levmax, 50);
contour(x, y, StreamFunction, levels)
hold on
theta = linspace(0, 2*pi);
plot(xGamma+cos(theta), yGamma+sin(theta), 'k-')
axis equal
axis([xmin, xmax, ymin, ymax])
ylabel('y')
xlabel('x')
I tried to use the definition u = diff(StreamFunction,y) and v = -diff(StreamFunction,x) , but it generates an error.
Could you help me?
Thank you very much!

채택된 답변

KSSV
KSSV 2020년 8월 4일
You should use gradient.
[u,v] = gradient(StreamFunction) ;
quiver(x,y,u,v)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by