How do i plot the function as a mesh in the constraint area only?
Show older comments
Given is the following conditions:
Using linprog()
Maximize: f= 30*X1 + 10*X2;
subject to : 6*X1 + 3*X2 <= 40;
3*X1 - X2<=0 ;
X1 + 0.25*X2 <= 4;
X1>=0
X2>=0
Display the plot
-the function as a mesh in the constraint area only (using mesh())
below is my approach ...please correct me.
f = [-30 -10];
A=[6 3;3 -1;1 0.25];
b=[40 0 4];
lb = zeros(2,1);
ub = [];
Aeq = [];
beq = [];
tic
options = optimoptions('linprog','Algorithm','dual-simplex','Display','iter');
[sol,fval,exitflag,output] = linprog(f,A,b,Aeq,beq,lb,ub,options);
toc
[X1 X2]=meshgrid(0:0.2:50,0:0.2:50);
cons1= 6*X1 + 3*X2 <= 40;
cons2= 3*X1 - X2<=0 ;
cons3= X1 + 0.25*X2 <= 4;
X1(~cons1)= NaN;
X1(~cons2)= NaN;
X1(~cons3)= NaN;
X2(~cons1)= NaN;
X2(~cons2)= NaN;
X2(~cons3)= NaN;
f= 30*X1 + 10*X2;
mesh(X1,X2,f);
Accepted Answer
More Answers (0)
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
