how to plot 3d inequalities on matlab

前端 未结 3 1701
情书的邮戳
情书的邮戳 2020-12-19 18:19

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          


        
3条回答
  •  时光说笑
    2020-12-19 19:04

    I don't understand several things in the code that you wrote as modification of @Tobold's help. For example what are the parameters p1 and p2 doing in your code?

    Anyway, The code plotting only the points of your grid satisfying all of your inequalities;

    [X,Y,Z]=meshgrid(0:0.1:1,0:0.1:1,0:0.1:1);
    ineq1 = (X >= 0 & X <= 1);
    ineq2 = (Y >= sqrt(X) & Y <= 1);
    ineq3 = (Z >= 0 & Z <= 1 - Y);
    all = ineq1 & ineq2 & ineq3;
    scatter3(X(all),Y(all),Z(all),'b','filled')
    

    The result is brought in the following image.

提交回复
热议问题