How to plot a velocity field

38 次查看(过去 30 天)
Andres Benoit
Andres Benoit 2020-12-21
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?

回答(1 个)

Divyajyoti Nayak
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)

类别

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