필터 지우기
필터 지우기

How to remove singularit​ies/discon​tinuities on 3D plots?

조회 수: 9 (최근 30일)
student_md
student_md 2022년 1월 5일
편집: John D'Errico 2022년 1월 7일
I want to plot some functions f(x,y) including singularities.
For example;
f(x,y)=tan(x-y)
  • In Matlab, when I run the following code
syms x y;
func=@(x,y) tan(x-y);
fsurf(@(x,y) func(x,y), [-4 2 -1 1])
I get
  • In Mathematica, when I plot same function, I can remove the discontinouties using Exclusions -> "Singularities"
In MATLAB, how to remove vertical asymptote lines in the Matlab's figure like Mathematica?
-How to find the asymptote lines in Matlab? After finding the asymptote, maybe we make it invisible in the plot..

답변 (1개)

John D'Errico
John D'Errico 2022년 1월 5일
There is no simple direct command to remove singularities. However, nothing stops you from setting the z axis limits.
syms x y;
func=@(x,y) tan(x-y);
fsurf(@(x,y) func(x,y), [-4 2 -1 1])
zlim([-5,5])
  댓글 수: 2
student_md
student_md 2022년 1월 6일
All right, how to remove vertical asymptote lines in your figure?
John D'Errico
John D'Errico 2022년 1월 7일
편집: John D'Errico 2022년 1월 7일
By the way, there was absolutely no need to use syms there. Defining the function as a function of the variables x and y is sufficient. That is, I needed do only as below.
The vertical lines will still be there, connecting each branch of the tangent function, from inf to -inf. Can you simply exclude them? Not that i can think of.
H = fsurf(@(x,y) tan(x-y), [-4 2 -1 1])
H =
FunctionSurface with properties: Function: @(x,y)tan(x-y) XRange: [-4 2] YRange: [-1 1] EdgeColor: [0 0 0] LineStyle: '-' FaceColor: 'interp' Show all properties
zlim([-5,5])
There is no assurance that you can always trivially do what another package does, down to the last bit. Could you do this? Well, I suppose, if you used meshgrid to create the surface, then replaced any elements larger than a max or smaller then a min with NaNs. But that would take a few more lines to write than the simple call to fsurf.
So without fsurf, where we cannot eliminate the unwanted vertical lines, we could have done this.
[x,y] = meshgrid(linspace(-4,2),linspace(-1,1));
func = @(x,y) tan(x-y);
z = func(x,y);
z((z > 5) | (z < -5)) = NaN;
surf(x,y,z)
xlabel x
ylabel y
zlabel z
grid on
box on
shading interp
colormap summer

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by