x = optimvar('x');
y = optimvar('y');
prob = optimproblem;
prob.Objective = -x -y/3;
prob.Constraints.cons1 = x + y <= 2;
prob.Constraints.cons2 = x + y/4 <= 1;
prob.Constraints.cons3 = x - y <= 2;
prob.Constraints.cons4 = x/4 + y >= -1;
prob.Constraints.cons5 = x + y >= 1;
prob.Constraints.cons6 = -x + y <= 2;
sol = solve(prob)
Solving problem using linprog.
Optimal solution found.
sol = struct with fields:
x: 0.6667
y: 1.3333
Find the value of the objective function at the solution.
Numeric value of expression, returned as a double.
Warning
The problem-based approach does not support complex values in an objective function, nonlinear
equalities, or nonlinear inequalities. If a function calculation has a complex
value, even as an intermediate value, the final result can be incorrect.