我不知道热绘制这个nonlp的可行性在MATLAB中 [英] I don't know hot to plot this nonlp's feasible reagion in matlab

查看:170
本文介绍了我不知道热绘制这个nonlp的可行性在MATLAB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索并观看了如何绘制nonlp程序的三个维度



,但我还是不知道如何绘制这些约束。



x ^ 2 + y ^ 2 + z ^ 2 = 1



x> = 2 * y

2 * y> = 3 * z

x> = 3 * z



我这样编程,但它不工作,我认为这是上限约束的错误程序。

  func1 = @(x,y,z)sqrt(1-x。^ 2-y 。^ 2); 
func2 = @(x,y,z)max(x-2 * y,0);
func3 = @(x,z)max(x-3 * z,0);
ezsurf(func1,[0 1 0 1]);
hold on;
ezsurf(func2,[0 1 0 1]);
hold on;
ezsurf(func3,[0 1 0 1]);
axis([0 1 0 1 0 1]);


解决方案

这样做的一种方式是使用体数据。



这个想法是创建一个具有 F 值的3D空间。 F 在您的主要方程式的一侧为正值,在另一侧为负值。

  [X,Y,Z] = meshgrid(-2:0.05:2,-2:0.05:2,-2:0.05:2) 

F = X. ^ 2 + Y. ^ 2 + Z. ^ 2-1;

然后条件应用于 F 。如果你想看到对象cut
,然后用 nan 替换条件不满足的地方。如果你想看到一个填充的对象,然后用一个正数(它可能需要在另一种情况下为负,因此请检查其他示例。)

 %条件
cond1 = X> = 2 * Y;
cond2 = 2 * Y> = 3 * Z;
cond3 = X> = 3 * Z ;

%如果你想要边界显示
F1 = F;
F1(〜cond1)= 1;
F1(〜cond2)= 1;
F1(〜cond3)= 1;

%如果你想要边界不显示
F2 = F;
F2(〜cond1)= NaN;
F2(〜cond2)= NaN;
F2(〜cond3)= NaN;

然后这个想法是在零级别(你的原始函数)创建一个等值面在这里代码我创建了2个图,所以你可以看到填充和不填充边界之间的差异还有一些花哨的编码,但是 isosurface patch 部分与获取表面和绘图相关。

  subplot(121)
iso1 = isosurface(X,Y,Z,F1,0);
p = ;
isonormals(X,Y,Z,F1,p);
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])$ ​​b $ b axis equal

camlight
lighting gouraud


subplot b $ b iso2 =等值面(X,Y,Z,F2,0);

p = patch(iso2);
isonormals(X,Y,Z,F2,p);
set(p,'FaceColor','red','EdgeColor','none');
axis equal

daspect([1 1 1])$ ​​b $ b camlight headlight
lighting gouraud

结果:





此外,您可以计算初始边界的等值面 F 并用低alpha值绘制它,以便更好地了解您实际选择的域的哪个部分。




I searched and watched how to plot the 3 dimensions of nonlp program's

but I still don't know how to plot these constraints.

x^2+y^2+z^2=1

x>=2*y
2*y>=3*z
x>=3*z

I programmed like this but it doesn't work and I think this is wrong program for upper constraints.

func1 = @(x,y,z) sqrt(1-x.^2-y.^2);
func2 = @(x,y,z) max(x-2*y,0);
func3 = @(x,z) max(x-3*z,0);
ezsurf(func1,[0 1 0 1]);
hold on;
ezsurf(func2,[0 1 0 1]);
hold on;
ezsurf(func3,[0 1 0 1]);
axis([0 1 0 1 0 1]);

解决方案

A way of doing that is to work with volumetric data.

The idea is to create a 3D space, with a F value. F will be positive in one side of your main equation and negative in the other.

[X,Y,Z]=meshgrid(-2:0.05:2,-2:0.05:2,-2:0.05:2);

F=X.^2+Y.^2+Z.^2-1;

Then the conditions are applied to this F. If you want to see the object "cut" then substitute the place where conditions are not met with nan. If you want to see a filled object, then substitute it with a positive number (it may need to be negative in another situation, so check this for other examples.

% Conditions
cond1=X>=2*Y;
cond2=2*Y>=3*Z;
cond3=X>=3*Z;

% If you want the boundaries to show
F1=F;
F1(~cond1)=1;
F1(~cond2)=1;
F1(~cond3)=1;

% If you want the boundaries not to show
F2=F;
F2(~cond1)=NaN;
F2(~cond2)=NaN;
F2(~cond3)=NaN;

Then the idea is to create an isosurface in the zero level (your original function). Here in this code I created 2 plots so you can see the differences between filling and not filling the boundaries. Also some fancy coding in order to get nice figures. However the isosurface and patch parts are relevant to obtain the surface and plot it.

subplot(121)
iso1=isosurface(X,Y,Z,F1,0);
p=patch(iso1);
isonormals(X,Y,Z,F1,p);
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
axis equal

camlight
lighting gouraud


subplot(122)
iso2=isosurface(X,Y,Z,F2,0);

p=patch(iso2);
isonormals(X,Y,Z,F2,p);
set(p,'FaceColor','red','EdgeColor','none');
axis equal

daspect([1 1 1])
camlight headlight
lighting gouraud

Result:

Additionally, You can calculate the isosurface of the initial boundary F and plot it with a low alpha value, so you can better understand what piece of the domain you are actually selecting.

这篇关于我不知道热绘制这个nonlp的可行性在MATLAB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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