cant use linprog for maximize

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.

 Accepted Answer

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 Comments

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);
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!

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 6 Dec 2014

Edited:

on 6 Dec 2014

Community Treasure Hunt

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

Start Hunting!