How to remove singularities/discontinuities on 3D plots?
조회 수: 15 (최근 30일)
이전 댓글 표시
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..
댓글 수: 0
답변 (1개)
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
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])
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 Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!