specifies matrix multiplication and exponentiation rather than
element-by-element multiplication and exponentiation. To specify
element-by-element operations, as is typically done with MESHGRID, you
need to add a '.' before each multiplication or exponentiation symbol.
You could replace the above line with:
z=(2.*(X.^3))-(3.*(X.^2))-(6.*X.*Y.*(X - Y - 1));