How to draw a 3D graph with constraints?

11 vues (au cours des 30 derniers jours)
DL
DL le 27 Oct 2019
Modifié(e) : Vikas Sharma le 11 Juin 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.

Réponse acceptée

John D'Errico
John D'Errico le 27 Oct 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 commentaires
Xiaohu Wu
Xiaohu Wu le 23 Sep 2020
A great example!
Vikas Sharma
Vikas Sharma le 11 Juin 2021
Modifié(e) : Vikas Sharma le 11 Juin 2021
Isn't it should x(~keepind)=NaN and y(~keepind)= NaN

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Construction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by