请问画三维曲面图时,​如果自变量的区间边界​是一个函数怎么办?

例如,用surf(X,Y,Z)画函数z(x,y)=x+y的三维曲面图,在XOY平面的范围是x=1,y=0,x=y围成的三角形区域,该怎么办?

 採用された回答

Rik
Rik 2020 年 3 月 30 日

0 投票

Use meshgrid or ndgrid to generate a full grid of coordinates. Then you mark all points outside your triangle with inpolygon. The surf function will ignore NaN values, so that is good choice.
You can make the grid as fine as you need it to be.
[X,Y]=ndgrid(linspace(0,1,50));
Z=X+Y;
%define the triangle here
xv=[0 1 1];
yv=[0 0 1];
L=inpolygon(X,Y,xv,yv);
X(~L)=NaN;
Y(~L)=NaN;
Z(~L)=NaN;
surf(X,Y,Z)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange光照、透明度和着色 についてさらに検索

タグ

質問済み:

2020 年 3 月 30 日

回答済み:

Rik
2020 年 3 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!