1

I am trying to solve a linear programming problem in matlab, the input is

[weights,~,flag]=linprog(f,[],[],C,b,0,10);

so, according to the manual this should solve the problem min f*x with the constraints C*x=b and 0<=x<=10. So all entries of x should be positive. However the solution I get contains negative entries (see example to reproduce the issue below). The flag i get back is 1, which according to the docs means the method has converged.

What am I doing wrong?

here is the input

C =

    19    20    18    20    18
     3     3     4     5     3
     1     1     1     1     2
     1     1     1     1     1

and

b =

    19
     4
     1
     1

and

f =

     1
     1
     1
     1

the result is

weights =

   84.1104
  -62.8328
  -41.5552
   21.2776
   -0.0000

1 Answer 1

2

OK, I found the problem: I thought the lower bound and the upper bound are scalars, but they are vectors, specifying for each coordinate what is its upper and lower bounds, so the correct way to call the function is

[weights,~,flag]=linprog(f,[],[],C,b,zeros(size(C,2),1,1),ones(size(C,2))*10);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.