Eas*_*sun 8 matlab wolfram-mathematica
例如,我想绘制函数
f(x,y) =sin(x^2+y^2)/(x^2+y^2), x^2+y^2 <=4?
Run Code Online (Sandbox Code Playgroud)
在Mathematica中,我可以这样做:
Plot3D[Sin[x^2 + y^2]/(x^2 + y^2), {x, -4, 4}, {y, -4, 4},
RegionFunction -> (#1^2 + #2^2 <= 4 Pi &)]
Run Code Online (Sandbox Code Playgroud)
其中RegionFunction指定x,y的区域来绘制.

这是一个不是特别优雅的解决方案,它将您不希望看到的区域的函数值设置为-infinity.
[x, y] = meshgrid(-4:0.1:4, -4:0.1:4);
z = sin(x.^2+y.^2)./(x.^2+y.^2);
idx = x.^2 + y.^2 > 4*pi;
z(idx) = -Inf;
surf(x, y, z); axis vis3d;
Run Code Online (Sandbox Code Playgroud)
编辑.实际上,如果你尝试更精细的网格(比如-4:0.01:4)并添加shading interp它看起来并不太糟糕.