![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/472897/image.png)
Plotting a multivariable function
조회 수: 6 (최근 30일)
이전 댓글 표시
I want to plot function f(x,y)=1/(x*y), but my code doesn't seem to work
x=[-3,0.1,3];
y=[-3,0.1,3];
[X,Y]=meshgrid(x,y);
Z=1./(X*Y);
surf(X,Y,Z)
댓글 수: 0
답변 (1개)
Image Analyst
2020년 12월 29일
You can do
% Original spacing
x=[-3,0.1,3];
y=[-3,0.1,3];
[X,Y]=meshgrid(x,y);
Z = 1 ./ (X .* Y);
subplot(2, 1, 1);
surf(X,Y,Z);
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
zlabel('Z', 'FontSize', 20);
colorbar;
but you are WAY undersampling this function to see the results, which essentially goes to infinity at X and Y both = 0.
% More fine spacing:
subplot(2, 1, 2);
numPoints = 700;
x = linspace(-3, 3, numPoints);
y = linspace(-3, 3, numPoints);
[X, Y] = meshgrid(x,y);
Z = 1 ./ (X .* Y);
surf(X,Y,Z, 'LineStyle', 'none');
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);
zlabel('Z', 'FontSize', 20);
colormap(jet);
colorbar;
xlim([-.05,.05]);
ylim([-.05,.05]);
zlim([-300, 1200]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/472897/image.png)
Your sampling at at the top while mine is at the bottom.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!