How to draw a 3D graph with constraints?

조회 수: 9 (최근 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 CenterFile Exchange에서 Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by