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

31 visualizaciones (últimos 30 días)
student_md
student_md el 5 de En. de 2022
Editada: John D'Errico el 7 de En. de 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..

Respuestas (1)

John D'Errico
John D'Errico el 5 de En. de 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 comentarios
student_md
student_md el 6 de En. de 2022
All right, how to remove vertical asymptote lines in your figure?
John D'Errico
John D'Errico el 7 de En. de 2022
Editada: John D'Errico el 7 de En. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by