[x,y]=meshgrid([-4:0.1:4]);
z = 4*y.^2 - x.^2;
surf(x,y,z)
Meshgrid creates a matrix x and y that look like this IF we used meshgrid([-4:1:4]), using 0.1 in the middle (the increment) would create much larger matrices no good for displaying
x =
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
-4 -3 -2 -1 0 1 2 3 4
y =
-4 -4 -4 -4 -4 -4 -4 -4 -4
-3 -3 -3 -3 -3 -3 -3 -3 -3
-2 -2 -2 -2 -2 -2 -2 -2 -2
-1 -1 -1 -1 -1 -1 -1 -1 -1
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4
Imagine looking down at the xy plane, along the z axis, the zeros of the x-matrix above would be the y-axis, and similarly the zeros in the y-matrix would be the x-axis.
Imagine overlaying the two matrices, and then plug each of the values at a given point into the equation, and that is your z at a given (x,y).
Use x.2 and y.2 instead of x2 or y2, the dot makes the power operation component-wise. x2 squared would be telling Matlab to multiply two matrices together.