Problem with using fcontour to plot functions involving arctan(x)

3 visualizaciones (últimos 30 días)
Ahmed Mohammed
Ahmed Mohammed el 3 de Nov. de 2023
Respondida: nick el 2 de En. de 2024
I am using the fcontour function to plot the streamline function for simulating various fluid flows. Below is an example of the code I am using:
syms y x;
U = 4; m = 30;
Epsi (x, y) = U*y + (m/(2*pi))*atan2(y+3, x+6) - (m/(2*pi))*atan2(y-3, x-6);
cla
fcontour(Epsi, [-15 15 -15 15], "LevelStep", 3,"LineColor", "black")
axis equal;
The issue I'm encountering is that the plots have these undesired stacked lines, primarily on the left side of the graph. I tried using the streamslice function to plot the same function, and it produced the following plot without the problematic lines:
I suspect that the problem may be related to the use of the atan2 function, which returns values in the range [-π, π]. The lines seem to occur at the boundaries of this output interval. Substituting atan in place of atan2 results in the lines appearing at π/2 and -π/2 (given the output limits of [-π/2, π/2]).
Is there a function that can replace atan2 and provide the correct plot, or is there a way to convert the output of atan2 to the [0, 2π] format (if this could resolve the issue)? Importantly, I need to retain the ability to use symbolic plotting options such as fcontour.
Due to specific restrictions within my application, I am unable to use non-symbolic plotting functions like contour, streamslice, etc.
  1 comentario
Star Strider
Star Strider el 4 de Nov. de 2023
Looking at the fsurf plot helps define the problem. There are step discontinuities at and the black bars are the result of several contour lines being spaced close together in those regions.
I am not certain what to suggest for a solution, since I do not understand what you are doing.
syms y x;
U = 4; m = 30;
Epsi (x, y) = U*y + (m/(2*pi))*atan2(y+3, x+6) - (m/(2*pi))*atan2(y-3, x-6);
cla
fcontour(Epsi, [-15 15 -15 15], "LevelStep", 3,"LineColor", "black")
axis equal;
figure
fsurf(Epsi, [-15 15 -15 15], 'MeshDensity',50, 'FaceAlpha',0.5)
hold on
plot3([0 0], [1 1]*pi, zlim, '-r')
plot3([0 0], -[1 1]*pi, zlim, '-r')
plot3(xlim, [1 1]*pi, [0 0], '-g', 'LineWidth',2)
plot3(xlim, -[1 1]*pi, [0 0], '-g', 'LineWidth',2)
hold off
colormap(turbo)
view(265,45)
xlabel('X')
ylabel('Y')
zlabel('Z')
.

Iniciar sesión para comentar.

Respuestas (1)

nick
nick el 2 de En. de 2024
Hi Ahmed,
I understand from your query that you need help in adjusting the output of arctan2” to the range [0,2*pi) format.
You can achieve this by using “mod” function which performs the modulo operation with divisor as 2*pi as shown below in the code snippet:
syms y x;
U = 4; m = 30;
Epsi (x, y) = U*y + (m/(2*pi))*atan2(y+3, x+6) - (m/(2*pi))*mod(atan2(y-3, x-6),2*pi);
cla
fcontour(Epsi, [-15 15 -15 15], "LevelStep", 6,"LineColor", "black","MeshDensity",4000)
axis equal;
You can also increase the “MeshDensity” for smoother and more accurate plots. While the simulation may take longer, this adjustment will provide more evaluation points and, consequently, a smoother curve. Here is the obtained output for the above snippet :
Figure 1 Output of “fcontour” at 4000 Mesh Density and 6 LevelStep
Hope this helps,
Regards,
Neelanshu

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by