如何绘制MATLAB的3D不平等 [英] how to plot 3d inequalities on matlab

查看:318
本文介绍了如何绘制MATLAB的3D不平等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制在MATLAB三维区域从一组不等式约束。

例如:

  0℃= X< = 1

开方(X)< = Y< = 1

0℃= z,其中= 1  - ÿ
 

我发现了一个二维的例子,有人做了这个网站,但我不知道如何将其转换成3D。 如何绘制不平等

编辑: 从@ Tobold的帮助我​​修改了code,以限制密谋那些由三个地区确定的点,但它绘制只有2或3分。它看起来像在向量X1点,Y1和Z1是正确的,但由于某种原因,它的绘制只是少数。任何想法,为什么它只是从X1绘制了几个点,Y1和Z1向量,而不是所有的人?

  [X,Y,Z] = meshgrid(0:0.1:1.0:0.1:1.0:0.1:1); %使0和1之间的点的网格
P1 = 0.1; P2 = 0.2; %选择一些参​​数
X1 =(X GT; = 0&安培; X  - 其中= 1)及(Y'GT; = SQRT(X)安培; Y&其中; = 1)及(Z> = 0&功放; Z< = 1  -  Y);
Y1 =(X GT; = 0&安培; X  - 其中= 1)及(Y'GT; = SQRT(X)安培; Y&其中; = 1)及(Z> = 0&功放; Z< = 1  -  Y);
Z1 =(X GT; = 0&安培; X  - 其中= 1)及(Y'GT; = SQRT(X)安培; Y&其中; = 1)及(Z> = 0&功放; Z< = 1  -  Y);
ineq1 =(X GT; = 0&安培; X  - 其中= 1)* 2;
ineq2 =(Y'GT; = SQRT(X)安培; Y&其中; = 1)* 4;
ineq3 =(Z> = 0&功放; Z< = 1  -  Y)* 8;
所有= ineq1和放大器; ineq2和放大器; ineq3;
颜色=零(尺寸(X))+ ineq1 + ineq2 + ineq3;
scatter3(X1(:),Y1(:),Z 1(:),3,颜色(:)','填充')
 

解决方案

我一直在试图找出了同样的事情,关键是让一切的大小不是在路口0 Tobold的scatter3行使用 3'作为用于大小选项,这意味着所有点将显示为点3。这可以代替相等大小的矩阵到X1与该组的大小。要做到这一点,最简单的方法就是让S = 3 *所有的:

 所有= ineq1和放大器; ineq2和放大器; ineq3;
颜色=零(尺寸(X))+所有;
大小= 3 *所有;
scatter3(X1(:),Y1(:),Z1(:),尺寸,颜色(:)','填补')
 

这应该让你在十字路口正好区域。

- 编辑:颜色变化需要改变了。你只需要在路口,而不是其他的不平等。

I want to plot a 3d region in MATLAB bounded from a set of inequalities.

For example:

0 <= x <= 1

sqrt(x) <= y <= 1

0 <= z <= 1 - y

I found a 2d example that someone has done on this site but I'm not sure how to convert that to 3d. How to plot inequalities.

Edit: From @Tobold's help I modified the code to restrict the points that are plotted to those that are defined by all three regions, but it plots only 2 or 3 points. It looks like the points in the vectors X1, Y1 and Z1 are right but for some reason its plotting only a few. Any ideas why it is only plotting a few points from the X1, Y1 and Z1 vectors instead of all of them?

[X,Y,Z]=meshgrid(0:0.1:1,0:0.1:1,0:0.1:1); % Make a grid of points between 0 and 1
p1=0.1; p2=0.2; % Choose some parameters
X1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y);
Y1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y);
Z1 = (X >= 0 & X <= 1) & (Y >= sqrt(X) & Y <= 1) & (Z >= 0 & Z <= 1 - Y);
ineq1 = (X >= 0 & X <= 1) * 2;
ineq2 = (Y >= sqrt(X) & Y <= 1) * 4;
ineq3 = (Z >= 0 & Z <= 1 - Y) * 8;
all = ineq1 & ineq2 & ineq3;
colors = zeros(size(X))+ineq1+ineq2+ineq3;
scatter3(X1(:),Y1(:),Z1(:),3,colors(:)','filled')

解决方案

I've been trying to figure out the same thing, and the trick is to make the size of everything not in the intersection 0. Tobold's scatter3 line uses '3' as the option for size, meaning all points will show up as point 3. This can be substituted for a matrix of equal size to X1 with the set of sizes. The easiest way to do this is just make s = 3*all:

all = ineq1 & ineq2 & ineq3;
colors = zeros(size(X))+all;
sizes = 3 * all;
scatter3(X1(:),Y1(:),Z1(:),sizes,colors(:)','filled')

That should get you just the area in the intersection.

-- edit: The color variable needs to change too. You just want the intersection, not the other inequalities.

这篇关于如何绘制MATLAB的3D不平等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆