The shapes of X, Y, and Z must match.  After the mesh grid, Z no longer matches X and Y.

Ben Root

(I will be out of contact for at least a week, sorry I won't be able to help any further till then.)