linear programming solution found unbounded but is bounded

10 ビュー (過去 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 Center および File ExchangeSolver 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