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

조회 수: 3 (최근 30일)
Ahmed Mohammed
Ahmed Mohammed 2023년 11월 3일
답변: nick 2024년 1월 2일
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
Star Strider
Star Strider 2023년 11월 4일
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')
.

댓글을 달려면 로그인하십시오.

답변 (1개)

nick
nick 2024년 1월 2일
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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by