I'm trying to plot the function $z = 6x^2 – 4x^2y^2$ in Matlab. The code I'm using for this in matlab is the one below, also the plot is shown:
v = [-2:0.1:2];
w = [-2:0.1:2];
[X,Y] = meshgrid(v,w);
Z = 6*X.^2-4*X.^2*Y.^2;
figure(3);
surf(X,Y,Z)
Now I when I plot this same function in Wolram Alpha I'm getting something different and I can't figure it out why. Here is the plot on Wolfram: Wolfram
Thanks!
Best Answer
When you have some problems with 3D plots in Matlab, it is often helpful to use different grids for $x$ and $y$. For example, if you change your code as
v = [-2:0.1:3];
, you will have a helpful error message:Error using *. Incorrect dimensions for matrix multiplication.
It means that you have matrix multiplication in your equation and not the element-wise. TryZ = 6*X.^2-4*X.^2.*Y.^2
.