gpt4 book ai didi

matlab - MATLAB 中 Mathematica 的 RegionPlot3D[] 的等价物是什么?

转载 作者:行者123 更新时间:2023-12-04 02:40:52 25 4
gpt4 key购买 nike

我想生成一个 3D 图,显示表示不等式组合的三维区域。在 Mathematica 中我使用 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]

生成:

enter image description here

我如何在 MATLAB 中做到这一点?

最佳答案

我认为 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 差。干杯。

parabola && sphere

关于matlab - MATLAB 中 Mathematica 的 RegionPlot3D[] 的等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com