Filter löschen
Filter löschen

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

9 Ansichten (letzte 30 Tage)
student_md
student_md am 5 Jan. 2022
Bearbeitet: John D'Errico am 7 Jan. 2022
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..

Antworten (1)

John D'Errico
John D'Errico am 5 Jan. 2022
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 Kommentare
student_md
student_md am 6 Jan. 2022
All right, how to remove vertical asymptote lines in your figure?
John D'Errico
John D'Errico am 7 Jan. 2022
Bearbeitet: John D'Errico am 7 Jan. 2022
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by