How to plot z = x^2 * y
Afficher commentaires plus anciens
x = linspace(-10, 10, 50);
y = linspace(-10, 10, 50);
[X,Y] = meshgrid(x,y);
Z = X.^2. * Y;
figure(1)
surf(X, Y, Z)
Don't know why the output just shows a flat surface
Réponses (1)
You have an extra space between "." and "*"
Z = X.^2. * Y;
% ^ space breaks up the .* operator
That causes Z to be the matrix product (*) of X.^2. and Y, which happens to result in a matrix containing one unique value very close to 0:
x = linspace(-10, 10, 50);
y = linspace(-10, 10, 50);
[X,Y] = meshgrid(x,y);
Z = X.^2. * Y;
unique(Z)
Remove the extra space, and you'll get Z to be the element-wise product (.*) of X.^2 and Y, as intended:
Z = X.^2.* Y;
surf(X, Y, Z)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
