How to draw a 3D graph with constraints?

8 ビュー (過去 30 日間)
DL
DL 2019 年 10 月 27 日
編集済み: Vikas Sharma 2021 年 6 月 11 日
I want to draw a 3D graph for a function with several contraints.
For example, f(x,y)=1-0.5*x-0.7*y such that 0<=x<=1, 0<=y<=1, 0<=x+y<=1.
Since I am a beginner of using MATLAB, so any help would be very appreciated.

採用された回答

John D'Errico
John D'Errico 2019 年 10 月 27 日
The simple answer is to just use meshgrid.
[x,y] = meshgrid(linspace(0,1,100));
keepind = (x + y) <= 1;
x(keepind) = NaN;
y(keepind) = NaN;
f = 1 - .5*x - .7*y;
surf(x,y,f)
  4 件のコメント
Xiaohu Wu
Xiaohu Wu 2020 年 9 月 23 日
A great example!
Vikas Sharma
Vikas Sharma 2021 年 6 月 11 日
編集済み: Vikas Sharma 2021 年 6 月 11 日
Isn't it should x(~keepind)=NaN and y(~keepind)= NaN

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConstruction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by