How do i plot the function as a mesh in the constraint area only?

조회 수: 3 (최근 30일)
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);
LP preprocessing removed 0 inequalities, 0 equalities, 0 variables, and added 0 non-zero elements. Iter Time Fval Primal Infeas Dual Infeas 0 0.037 0.000000e+00 0.000000e+00 1.335997e+01 2 0.06 -1.600000e+02 2.057442e+00 0.000000e+00 3 0.06 -1.466667e+02 0.000000e+00 0.000000e+00 Optimal solution found.
toc
Elapsed time is 1.673879 seconds.
[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);

채택된 답변

yanqi liu
yanqi liu 2021년 11월 22일
sir,which is the question?
clc; clear all; close all;
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);
LP preprocessing removed 0 inequalities, 0 equalities, 0 variables, and added 0 non-zero elements. Iter Time Fval Primal Infeas Dual Infeas 0 0.098 0.000000e+00 0.000000e+00 1.335997e+01 2 0.136 -1.600000e+02 2.057442e+00 0.000000e+00 3 0.137 -1.466667e+02 0.000000e+00 0.000000e+00 Optimal solution found.
toc
Elapsed time is 2.145769 seconds.
[X1, X2]=meshgrid(0:0.1:20,0:0.1:20);
cons1= 6*X1 + 3*X2 <= 40;
cons2= 3*X1 - X2<=0 ;
cons3= X1 + 0.25*X2 <= 4;
X1(~(cons1&cons2&cons1))= NaN;
X2(~(cons1&cons2&cons1))= NaN;
f= 30*X1 + 10*X2;
mesh(X1,X2,-f);
xlabel('X1')
ylabel('X2')
zlabel('f')
hold on;
plot3(sol(1),sol(2),fval,'ro','MarkerFaceColor', 'r');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by