MATLAB Error using .*. Matrix dimensions must agree
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Guillaume
on 25 Feb 2015
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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!