cant use linprog for maximize

2 Ansichten (letzte 30 Tage)
Ivan
Ivan am 6 Dez. 2014
Bearbeitet: John D'Errico am 6 Dez. 2014
I have my function fx= -0.818x1 + 0.241x2 + 4.737x3 + 0.2x4 + 0.483x5 - 0.02x6 + 0.06x7. And I have some constrains: 1. fx cant be larger than 100
2. 22=<x1=<40
3. 52=<x2=<80
4. 3.5=<x3=<5.9
5. 12=<x4=<22
6. 105=<x5=<150
7. 300=<x6=<700
8. 800=<x7=<1200
9. x4+x3=21
10. x5-x2=50
Please, show me the code of this optimization.

Akzeptierte Antwort

John D'Errico
John D'Errico am 6 Dez. 2014
Isn't this basically the same question you asked before? You have added a couple of equality constraints only.
I won't even bother to copy over the rest of your code from your last question. Just pass in these additional two variables now into linprog (where you previously passed in [] as placeholders when you had no equality constraints.)
Aeq = [0 0 1 1 0 0 0;0 -1 0 0 1 0 0];
beq = [21;50];
  2 Kommentare
Ivan
Ivan am 6 Dez. 2014
man, I have some doubts of my code.
Basically linprog works for minimization. So for max, I have to invert my main function, which I did. But, do i have to invert this lines:
A = [-0.818 0.241 4.737 0.2 0.483 -0.02 0.06];
b = [100];
The question is:
[x,fval] = linprog(-f,A,b,[],[],lb,ub);
or
[x,fval] = linprog(-f,-A,-b,[],[],lb,ub);
John D'Errico
John D'Errico am 6 Dez. 2014
Bearbeitet: John D'Errico am 6 Dez. 2014
READ THE HELP!!!!!!! I'll paste in the relevant lines...
min f'*x subject to: A*x <= b
x
You changed the sign of f, ONLY because you wanted to maximize the function, not minimize. That changes nothing else though.
However, if you pass in -A and -b, then do you think that you will actually be trying to solve the problem
-A*x <= -b
which is equivalent to
A*x >= b
It seems to me that would not be solving the problem you have posed.
READ THE HELP! THINK!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by