MATLAB: MATLAB Error using .*. Matrix dimensions must agree

3d plotsMATLAB

Hello!
Could you help me with the next?
I'm trying to plot a 3d graph writing this:
u = linspace(0,pi,60);
v = linspace(0,pi,60);
x = cos(v).*sqrt(abs(sin(2.*u))).*cos(u);
y = cos(v).*sqrt(abs(sin(2.*u))).*sin(u);
[X,Y] = meshgrid(x,y);
Z = X.^2 - Y.^2 + 2.*X.*Y.*(tan(v)).^2;
surf(X,Y,Z);
But I'm getting an error that tells:
Error in m07 (line 6):
Z = X.^2 - Y.^2 + 2.*X.*Y.*(tan(v)).^2;
What's wrong?
Thanks for your help.

Best Answer

Well X and Y are 60x60 matrices whereas V and thus tan(V).^2 are 1x60 vectors. You can't multiply the two together elementwise since they don't have the same number of elements.
You must have meant something else than tan(V) in the second part of your expression.