3

I want to generate a 3D plot that shows the three-dimensional region representing a combination of inequalities. In Mathematica I use RegionPlot3D[]:

RegionPlot3D[
 x^2 + y^2 + z^2 < 1 && x^2 + y^2 < z^2, {x, -1, 1}, {y, -1, 
  1}, {z, -1, 1}, PlotPoints -> 35, PlotRange -> All]

which generates:

enter image description here

How can I do that in MATLAB?

4

1 回答 1

4

我认为 MATLAB 中没有等效的函数RegionPlot3D。但是,您可以surf用来制作 3D 曲面图并以数学方式设计输出。例如,您的代码可以在 MATLAB 中重写为:

m=100;
n=100;

% set up the domain points
x = linspace(-1,1,m);
y = linspace(-1,1,n);

% set up the range points
z1 = nan(m,n);
z2 = nan(m,n);
for i=1:m
    for j=1:n
        zSquared = x(i)^2+y(j)^2; % z^2
        if zSquared<=1/2
            z1(i,j) = sqrt(zSquared); % the parabola
            z2(i,j) = sqrt(1-zSquared); % the ball
        end
    end
end

AxesHandle=axes();
grid on;
hold(AxesHandle,'all');
surf(AxesHandle,x,y,z1,'EdgeColor','none'); % top part
surf(AxesHandle,x,y,z2,'EdgeColor','none');
surf(AxesHandle,x,y,-z1,'EdgeColor','none'); % bottom part
surf(AxesHandle,x,y,-z2,'EdgeColor','none');
view([-55,16]);

图形虽然比 Mathematica 差。干杯。

抛物线 && 球面

于 2013-11-14T06:37:06.927 回答