Linprog gives a solution but one constraint is not satisfied (no notification)

7 visualizaciones (últimos 30 días)
Hi!
I am trying to solve a linear programming problem with LinProg where I try to maximize x1 and (in another application) maximize the sum of a vector, subject to some constraints. Now my problem is that the software provides a solution but when I check this with the constraint, in both applications the first constraint is not satisfied. I checked that I didn't write any negatives when there should be a positive or the other way around but the constraint seems fine. It has the same structure as the others and comes from the same data set so there should be no problem here.
Does anyone know what could be the problem here?
Thank you in advance!!!

Respuesta aceptada

Torsten
Torsten el 16 de Dic. de 2021
I get
x3(1) = 387,2108
x3(3) = 7,5211
x3(9) = 4,8920
x3(10) = 0.3761
and x3(i) = 0 for all other components.
And this vector is feasible as you can see when you print out
constraints3*x3-b3
eq'*x3-400

Más respuestas (2)

John D'Errico
John D'Errico el 16 de Dic. de 2021
Editada: John D'Errico el 16 de Dic. de 2021
Not possible to know, since you don't actually show us the code you wrote. You may have done something wrong.
Or it may just be your understanding of what it means to satisfy a constraint, in terms of floating point arithmetic and the constraint tolerance. That is, is the constraint satisfied WITHIN the constraint tolerance?
Beyond that, my crystal ball tells me only that you may soon come into a large sum of money. Or maybe it is telling me that your relatives may soon inherit a large sum of money from you. It is very unclear. These darned crystal balls. ;-)
Seriously, if you want a better answer, you need to show code we can look at and verify to know where you are going wrong.
  6 comentarios
Matt J
Matt J el 16 de Dic. de 2021
Editada: Matt J el 16 de Dic. de 2021
Your zmatrix has only 23 elements in it, instead of 31. It would be easiest if you simply attached f3, constraints, and b3 in a .mat file directly.
One suggestion I can make though is not to express your constraint data in units of milligrams and micrograms. Express them in kilograms so that you won't have such huge numbers.
Torsten
Torsten el 16 de Dic. de 2021
Your zmatrix has only 23 elements in it, instead of 31.
W3' is 23x31, x3 is 31x1, b3' is 23x1.

Iniciar sesión para comentar.


Matt J
Matt J el 16 de Dic. de 2021
Editada: Matt J el 16 de Dic. de 2021
load data
defaultOptions=optimoptions('linprog');
[x3,fval,exitflag,output] = linprog(f3,constraints3,b3,eq',400,lb3,[], defaultOptions);
Optimal solution found.
The constraint violation is quite small, certainly smaller than the default tolerance, although I don't know if that's supposed to be an absolute or relative tolerance.
output.constrviolation
ans = 2.9802e-08
defaultOptions.ConstraintTolerance
ans = 1.0000e-04
It is also insignificant compared to the typical magnitudes of your constraints:
min(b3-constraints3*x3)
ans = -2.9802e-08
median(b3-constraints3*x3)
ans = 1.5049e+08

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by