How to draw a 3D graph with constraints?

9 次查看(过去 30 天)
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 个评论
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