How to draw a 3D graph with constraints?

7 visualizaciones (últimos 30 días)
DL
DL el 27 de Oct. de 2019
Editada: Vikas Sharma el 11 de Jun. de 2021
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.

Respuesta aceptada

John D'Errico
John D'Errico el 27 de Oct. de 2019
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 comentarios
Xiaohu Wu
Xiaohu Wu el 23 de Sept. de 2020
A great example!
Vikas Sharma
Vikas Sharma el 11 de Jun. de 2021
Editada: Vikas Sharma el 11 de Jun. de 2021
Isn't it should x(~keepind)=NaN and y(~keepind)= NaN

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Construction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by