Different results using mesh and surf

1 visualización (últimos 30 días)
Nathan Shapiro
Nathan Shapiro el 5 de Oct. de 2020
Comentada: Adam Danz el 5 de Oct. de 2020
I'm trying to graph the function xye^(-(x.^2+y.^2)), and I used both surf and mesh to do so. Below is the code. The problem is the two graphs are different. The surf function seems to have gotten it correct, but the mesh function looks like it graphed the absolute value of the function. Why is there this difference?
clear
clc
r=100;
x1 = linspace(-10,10,r);
y2 = linspace(-10,10,r);
[x,y] = meshgrid(x1,y2);
z=x.*y.*exp(-(x.^2+y.^2));
figure
surf(x,y,z)
xlabel('x');
ylabel('y');
zlabel('z');
grid on
shading interp
colorbar
figure
mesh(x,y,z.^2)
xlabel('x');
ylabel('y');
zlabel('z');
grid on

Respuesta aceptada

Adam Danz
Adam Danz el 5 de Oct. de 2020
Editada: Adam Danz el 5 de Oct. de 2020
> The problem is the two graphs are different. The surf function seems to have gotten it correct, but the mesh function looks like it graphed the absolute value of the function
Hint
mesh(x,y,z.^2)
% ^^^
Also see the difference in the z-axis values. The range of z values in the mesh version is not the absolute value of the z values in the surf version, it's squared (which forces negative values to be positive).
  2 comentarios
Nathan Shapiro
Nathan Shapiro el 5 de Oct. de 2020
Oh, I can't believe I missed that. Thank you for your help!
Adam Danz
Adam Danz el 5 de Oct. de 2020
Sometimes a 2nd pair of eye is all that's needed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by