How to plot a velocity field

38 views (last 30 days)
Andres Benoit
Andres Benoit on 21 Dec 2020
Answered: Divyajyoti Nayak on 11 Sep 2024
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?

Answers (1)

Divyajyoti Nayak
Divyajyoti Nayak on 11 Sep 2024
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)

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!