How to plot a velocity field
조회 수: 37 (최근 30일)
이전 댓글 표시
I want to plot a velocity field defined in polar coodinates as Vr = -10/r and Vt=10/r (radial and tangent coordinates, respectively), but im having some troubles, below the code that i made.
x = -4:0.3:4;
y = x;
[X, Y] = meshgrid(x,y);
Vr = -10./sqrt(X.^2 + Y.^2);
Vt = 10./sqrt(X.^2 + Y.^2);
quiver(x, y, Vr,Vt)
How can i plot it correctly?
댓글 수: 0
답변 (1개)
Divyajyoti Nayak
2024년 9월 11일
Hi Andres,
I see that you are trying to plot a velocity field defined in polar coordinates using the ‘quiver’ function. The ‘quiver’ function however requires the velocity to be defined in cartesian coordinates. Here’s a documentation link for the ‘quiver’ function:
To plot the velocity field, convert the velocity components from polar coordinates to cartesian coordinates. Here’s a sample code that might help:
clear
clc
x = linspace(-4,4,27);
y = x;
[X, Y] = meshgrid(x,y);
r = sqrt(X.^2 + Y.^2); % r in function of (x, y)
theta = atan2(Y,X); % theta in function of (x, y)
Vr = -10./r;
Vt = 10./r;
u = Vt.*sin(theta) + Vr .* cos(theta);
v = Vt.*cos(theta) - Vr.*sin(theta);
figure
quiver(X, Y, u,v)
댓글 수: 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!