How to plot z = x^2 * y
이전 댓글 표시
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
답변 (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)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
