Maximize z in the following linear program:

I have a question about Linear program
Given A = [1 1; -1 1; 0 -1], b = [10;10;0]
maximize z
subject to A(i) * x + z ≤ b(i) ∀i ∈{2,3}
-A(t) * x + z ≤ -b(t) ∀t ∈{1}
z ≤ 1 \\* or any other constant

8 Comments

Look into linprog.
What have you tried yet?
I have but the problem is unbounded:
x =[]
Here is my code
A = [1 1; -1 1; 0 -1]; b = [10;10;0];
f = zeros(size(A, 2) + 1, 1); % +1 for the z variable
i = [2,3]; t = [1]
% Define the inequality constraints for cplus and cminus
A_ineq = [A(i, :); -A(t, :)];
b_ineq = [b(i); -b(t)];
% Define the upper bounds for variables (no upper bound for x, z <= 1)
lb = -Inf(size(f));
ub = ones(size(f));
ub(end) = 1; % z <= 1
% Solve the linear program using linprog
options = optimset('Display', 'off'); % Suppress solver output
[x_z, ~, exitflag] = linprog(f, [], [], A_ineq, b_ineq, lb, ub, options);
The problem formulaton does not do anything with the matrix A. Additionally, there is a vector a that has not been defined.
@Matt J: I have edited the question. It was a typo. I intended for A
I get
x = [10 1]
z = 1
as solution.
A = [1 1; -1 1; 0 -1]; b = [10;10;0];
f = [0 0 -1];
i = [2,3]; t = [1];
% Define the inequality constraints for cplus and cminus
A_ineq = [A(i, :) ones(2,1); -A(t, :) ones(1,1)];
b_ineq = [b(i); -b(t)];
% Define the upper bounds for variables (no upper bound for x, z <= 1)
lb = -Inf(size(f));
ub = Inf(size(f));
ub(end) = 1; % z <= 1
% Solve the linear program using linprog
options = optimset('Display', 'off'); % Suppress solver output
[x_z, ~, exitflag] = linprog(f, A_ineq, b_ineq, [],[],lb, ub, options)
x_z = 3×1
10 1 1
exitflag = 1
@Torsten: Could you share your code becauise I get

Sign in to comment.

Answers (0)

Products

Asked:

on 24 Sep 2023

Commented:

on 24 Sep 2023

Community Treasure Hunt

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

Start Hunting!