How can I change the convergence condition in linprog?

3 views (last 30 days)
I have very simple linear program as follows
min 150*x1+230*x2+260*x3
subject to
x1+x2+x3<=500
x1,x2,x3>=0
The optimal solution of the above problem is trivial and it is x=0. To solve this problem, I run the following code
f=[150;230;260];
A=[1 1 1];
b=500;
x=linprog(f,A,b,[],[],zeros(3,1));
and I obtain
x =
1.0e-11 *
0.9929
0.7471
0.6562
To obtain the exact solution (i.e., x=0), what can I do?
Thank you in advance,
Derya

Answers (1)

Alan Weiss
Alan Weiss on 14 Apr 2015
There are different approaches depending on which MATLAB version you are running. The reason for the slight inaccuracy is that the default linprog algorithm is 'interior-point', which is fast and robust but can lead to slight inaccuracies in the reported solution.
So the solution for you is not to use an interior-point solver if you want the most accuracy (but you can lose robustness, memory efficiency, and solver time). For example,
options = optimoptions('linprog','Algorithm','active-set');
f=[150;230;260];
A=[1 1 1];
b=500;
x=linprog(f,A,b,[],[],zeros(3,1),[],[],options);
returns the following on my computer:
Optimization terminated.
x =
0
0
0
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 14 Apr 2015
optimoptions was introduced in R2013a. For your MATLAB version, as documented the way to use the simplex algorithm is
options = optimset('LargeScale', 'off', 'Simplex', 'on');
x = linprog(f,A,b,[],[],zeros(3,1),[],[],options);
You could also try using the medium scale algorithm by simply setting
options = optimset('LargeScale', 'off');
Alan Weiss
MATLAB mathematical toolbox documentation
DD
DD on 14 Apr 2015
It seems that I was making mistake while using "options". You solved my problem :) Thank you Alan.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!