linear programming solution found unbounded but is bounded

조회 수: 11 (최근 30일)
Eric Kathe
Eric Kathe 2021년 2월 7일
댓글: Eric Kathe 2021년 2월 11일
%% linear programing problem
% minimize Z = 2*x1 + 3*x2 subject to
% 0.5*x1 + 0.25*x2 <= 4 and
% x1 + 3*x2 >= 20. Negate both sides of 2nd constraint as
% -x1 + -3*x2 <= -20
% define xv = [x1;x2], b = [4;-20], A = [0.5 0.25;-1 -3], and f = [2;3] so
% Z = f'*xv and A*x <= b. I try solving this at the end of this file.
% First, let's graphically solve it.
%% create line vectors for graphic solution
x1v = linspace(0,20,100); % span viable domain of x1
x2v = linspace(0,16,101); % span viable domain of x2
x2c1 = (4 -(1/2)*x1v)/(1/4);% constraint 1 equality
x2c2 = (20 - x1v)/3; % constraint 2 equality
%% apriori known solution at 2nd constraint at x1 = 0
x1s = 0;
x2s = 20/3;
%% cost function over domain of x1v and x2v
[X1,X2] = meshgrid(x1v,x2v); % create matrix x1 and x2 values
% I made x2v longer than x1v to ease knowing orientation of X1, X2, & Z
Z = 2*X1 + 3*X2; % compute Z at each set of points
cv = 0:5:(2*max(x1v)+3*max(x2v)); % contour levels for later plotting
%% plot space
figure(1)
hp = patch([x1s 0 5.6 x1s],... % (5.6,4.8) intersection of constraints
[x2s 16 4.8 x2s],'y'); % patch feasible domain
set(hp,'LineStyle','none')
hold on
[Cc,hc] = contour(X1,X2,Z,cv); % plot and label Z contours
clabel(Cc,hc)
hg = plot(x1v,x2c1,'b--',... % plot constraint equality lines
x1v,x2c2,'r-',... %
x1s,x2s,'kp'); % plot solution point
hold off
grid on
legend('feasible region','cost function','<= constraint',...
'>= constraint','optimal solution')
axis([0 max(x1v) 0 max(x2v)])
axis('equal')
xlabel('x_1')
ylabel('x_2')
title('minimization problem with >= and <= constraints')
%% try to use Matlab's optimization toolbox
A = [(1/2) (1/4)
-1 -3];
b = [4;-20];
f = [2 3];
[xs,fval] = linprog(f,A,b);
gives the error "Problem is unbounded."
Note, Wolfram's alpha has a tool that solves it at

채택된 답변

Matt J
Matt J 2021년 2월 8일
편집: Matt J 2021년 2월 8일
Note, Wolfram's alpha has a tool that solves it
No, the Wolfram tool finds it to be unbounded as well. Are there supposed to be positivity constraints? If so, you've omitted them.
  댓글 수: 1
Eric Kathe
Eric Kathe 2021년 2월 11일
Thank you for the response. My error. Stadard textbook form presumes non-negative variables. I need to add a lower bound to enforce this as:
lb = [0,0]; ub = [inf,inf];
[xs,fval] = linprog(f,A,b,[],[],lb,ub);
When I tried Wolfram, the example already had such a lower bound. In the graphical solution posted with the question, it is presumed.
The lower bound becomes the active constraint with x1 = 0. Without it, the solution for x1 drifts to -inf.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by