Different 3D plot in MATLAB and Wolfram Alpha

MATLABwolfram alpha

I am trying to plot the function of two variables $f(x,y) = e^{xy}, -2 \leq x \leq 2, -1 \leq y \leq 3$ in MATLAB. Here's the code I'm using:

x = [-2:0.1:2]; 
y = [-1:0.1:3];
[X,Y] = meshgrid(x,y);
Z = exp(X.*Y);
surf(X,Y,Z);

Now, when I run this code I get the followingenter image description here

If I try to plot the same surface with Wolfram Alpha, I get something quite different: f(x,y) with Wolfram Alpha

I tried to update the version of MATLAB (I'm currently using 9.12.0 (R2022a)) but that didn't solve the issue.

Thank you!

Best Answer

The WolframAlpha plot did two things: first, it ignored your $y$ range, and instead plotted the function on the square roughly approximating $(x,y) \in [-1.75, 1.75]^2$. I have no idea why it would select this region to plot; you can see in both the contour plot and the 3D plot, the axis doesn't go all the way to $\pm 2$. Second, it truncated the vertical axis to plot only the range $f(x,y) \in [0,5.5]$. The reason for this is at least a bit more clear: WolframAlpha uses an algorithm to pick the plot range that shows the most "interesting" features of the plot. If you select the full plot range, the curvature of the region close to the origin is not as immediately obvious.

Here are some plots in Mathematica to compare, and the syntax used to generate them:

This command tries to reproduce the Wolfram Alpha plot as faithfully as possible.

Plot3D[Exp[x y], {x, -1.75, 1.75}, {y, -1.75, 1.75}, PlotRange -> {0, 5.5}, BoxRatios -> Automatic]

enter image description here

This command plots on the square $[-2,2]^2$, showing that the region that Wolfram Alpha chose doesn't correspond to any of the specified plot limits in the original input:

Plot3D[Exp[x y], {x, -2, 2}, {y, -2, 2}, PlotRange -> {0, 5.5}, BoxRatios -> Automatic]

enter image description here

This command plots the actual input as specified in the Wolfram Alpha query, but keeps the limited vertical axis range:

Plot3D[Exp[x y], {x, -2, 2}, {y, -1, 3}, PlotRange -> {0, 5.5}, BoxRatios -> Automatic]

enter image description here

Finally, this command forces the full range to be plotted, and corresponds to the Matlab output:

Plot3D[Exp[x y], {x, -2, 2}, {y, -1, 3}, PlotRange -> All, BoxRatios -> {1, 1, 1}]

enter image description here

Related Question