Asked by Edward Xu
on 14 Sep 2018

I am trying to solve a linear optimization problem, and I have followed the steps of the guide in MATLAB website. And I get the minus result. I am pretty sure the max is 36000.

linearOptim = optimproblem('ObjectiveSense','maximize');

product_1 = optimvar('product_1', 'Type', 'integer', 'LowerBound', 0);

product_2 = optimvar('product_2', 'Type', 'integer', 'LowerBound', 0);

linearOptim.Objective = 3000 * product_1 + 5000 * product_2;

linearOptim.Constraints.econs1 = product_1 <= 4;

linearOptim.Constraints.econs2 = 2 * product_2 <= 12;

linearOptim.Constraints.econs3 = 3 * product_1 + 2 * product_2 <= 18;

showproblem(linearOptim);

solveLinearOptim = solve(linearOptim);

Answer by Alan Weiss
on 14 Sep 2018

Edited by Alan Weiss
on 14 Sep 2018

You are seeing the underlying solver's intermediate calculations. But if you look at the returned function value, you get the correct answer. For example,

evaluate(linearOptim.Objective,solveLinearOptim)

ans =

36000

Or even more simply, in the function call itself:

[solveLinearOptim,fval] = solve(linearOptim)

LP: Optimal objective value is -36000.000000. % This is the confusing bit

**snip**

solveLinearOptim =

struct with fields:

product_1: 2.0000

product_2: 6

fval =

36000 % This is the correct answer

Alan Weiss

MATLAB mathematical toolbox documentation

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418992-why-i-get-the-minus-result-for-linear-optimization#comment_610308

## Edward Xu (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418992-why-i-get-the-minus-result-for-linear-optimization#comment_610331

## Torsten (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418992-why-i-get-the-minus-result-for-linear-optimization#comment_610338

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418992-why-i-get-the-minus-result-for-linear-optimization#comment_610340

Sign in to comment.