Trying to plot streamlines and need some help
37 次查看(过去 30 天)
显示 更早的评论
Hey everyone, I'm trying to plot the streamline of a rotating cylinder but when I run my code, I get a weird graph. If anyone can take a look and let me know what I can change, I'll really appraicate it.
clc
clear
close all
syms x y
x_axis = linspace(-1,1,50);
y_axis = linspace(-1,1,50);
[x,y] = meshgrid(x_axis,y_axis)
% need to convert cartensian to cylinderical%
r = sqrt((x.^2)+(y.^2));
theta = atan2(y./r,x./r);
U_flow = 100
a = 10
gamma = 100
velocity_pot = U_flow*r*cos(theta)*(1 + (a.^2./r^2))
u_r = (1 - r.^-2)*cos(theta)
u_o = - (1 + r.^-2)*sin(theta)
%u = diff(Velocity_pot,x);
%v = diff(Velocity_pot,y);
figure(1)
quiver(x,y,u_r,u_o)
% figure(2)
% contour(x,y,velocity_pot,[-1:1:6])
回答(2 个)
Umar
2024-10-20
编辑:Torsten
2024-10-20
Hi @Britney,
To address your query regarding plotting the streamlines of a rotating cylinder, let me first analyze the context and the issues you're facing. It appears that you are trying to visualize the flow field around a rotating cylinder but are encountering unexpected results in your graph. The main components of your code involve defining a grid, calculating velocities in cylindrical coordinates, and plotting with quiver. The key themes are listed below.
_Flow Field Calculation:_ You are using cylindrical coordinates to model the flow around a rotating cylinder.
_Visualization:_ The quiver function is being used for vector field visualization, which may not be yielding the expected results due to the nature of your velocity calculations or grid definitions. Here is an updated version of your code with detailed explanations and corrections:
clc;
clear;
close all;
% Define the grid for the x and y coordinates
x_axis = linspace(-1, 1, 50);
y_axis = linspace(-1, 1, 50);
[x, y] = meshgrid(x_axis, y_axis);
% Convert Cartesian to Polar Coordinates
r = sqrt(x.^2 + y.^2); % Radial distance
theta = atan2(y, x); % Angle
% Flow parameters
U_flow = 100; % Flow velocity
a = 10; % Parameter related to the cylinder
gamma = 100; % Circulation strength
% Calculate velocity potential
velocity_pot = U_flow * r .* cos(theta) .* (1 + (a^2 ./ r.^2));
%Calculate radial and angular components of velocity
u_r = (1 - r.^-2) .* cos(theta);
u_o = -(1 + r.^-2) .* sin(theta);
% Plotting the vector field using quiver
figure(1);
quiver(x, y, u_r, u_o);
axis equal; % Equal scaling for x and y axes
title('Velocity Field Around a Rotating Cylinder');
xlabel('X-axis');
ylabel('Y-axis');
grid on;
% Optional: Add streamlines for better visualization
hold on;
streamline(x, y, u_r, u_o, x(1:5:end), y(1:5:end)); % Adjust for streamline
density
hold off;
Let me explain the changes made in the code below.
_Grid Definition:_ Ensure that x and y meshgrid creation is correct.
_Cylindrical Conversion:_ The conversion from Cartesian to cylindrical coordinates is maintained correctly.
_Velocity Components:_ Ensure that you are correctly defining the radial (u_r) and angular (u_o) components based on the physical model you want to represent.
_Quiver Plot:_ Used quiver to plot the velocity vectors while ensuring equal axis scaling for proper representation.
_Streamlines:_ Added optional streamlines using streamline function for visual clarity. For more information on this function, please refer to
<https://www.mathworks.com/help/matlab/ref/streamline.html>
Please see attached.
<</matlabcentral/answers/uploaded_files/1796030/IMG_8165.jpeg>>
You might want to experiment with different values for U_flow, a, and gamma to see how they affect the flow field. Also, increasing the resolution of your meshgrid can lead to smoother visualizations.
This structured approach should help clarify your visualizations and provide you with a clearer representation of the flow around a rotating cylinder.
If you have further issues or specific outputs that still appear incorrect, please provide additional details so we can refine our approach.
0 个评论
Divyajyoti Nayak
2024-10-20
编辑:Divyajyoti Nayak
2024-10-20
I am assuming that you're trying to plot the streamlines of the potential flow around a cylinder of radius "a". To do so, the "streamline" function can be used, Here's the documentation for the same:
To use the "streamline" function, the radial and tangential velocity need to be converted to velocity in x and y direction. Before that, there are some corrections to be made in calculation of radial and tangential velocity. The radius of the cylinder, "a" is 10 which is bigger than the grid created. The cylinder radius should be some value less than 1, such as 0.3, and needs to be in the calculation of velocities. Moreover, the radial and tangential velocities are being calculated using matrix multiplication with "sin(theta)" and "cos(theta)", when they should be multiplied element wise. Also ideally, the flow velocity should also be multiplied. Here's the corrected code implementing all these fixes:
a = 0.3;
gamma = 100;
velocity_pot = U_flow*r.*cos(theta).*(1 + (a.^2./r^2));
u_r = U_flow.*(1 - (a./r).^2).*cos(theta);
u_o = -1*U_flow.*(1 + (a./r).^2).*sin(theta);
Now here's the code to convert the velocities from polar to cartesian form:
u_x = u_r.*cos(theta) - u_o.*sin(theta);
u_y = u_r.*sin(theta) + u_o.*cos(theta);
Lastly, to plot the streamlines, the "streamline" function can be used:
figure(1)
start_x = x(:,1); %X values of streamline starting point
start_y = y(:,1); %Y values of streamline starting point
streamline(x,y,u_x,u_y,start_x,start_y);
axis equal
Here's the final plot:
Hope this helps!
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!