matlablinear-programmingequation-solvinglinear-equationmaximization

Linear programming maximization code in MATLAB


How to solve the linear programming maximization problem that contains both <= and >= equations?

For example here's a case:

Maximize:

z = c1x1 + c2x2 + c3x3

Subject to:

a1x1 + a2x2 + a3x3 <= b1
a4x1 + a5x2 + a6x3 <= b2
x1 >= d1
x2 >= d2
x3 >= d3

Where a1, a2, a3, a4, a5, a6, b1, b2, b3, c1, c2, c3 are the constants in the given equations.

What will be the proper Matlab code to solve this problem?


Solution

  • That's how :

        z = -[c1 ; c2 ; c3];
    
        A = [ a1 a2 a3 ; 
              a4 a5 a6]; 
    
        b=[b1;
           b2];
    
        Aeq= [ ]; beq= [ ];
    
        LB = [d1 ; d2 ; d3]; 
    
        UB = [1 ; 1 ; 1]* inf; % Any relax number
    
        x = linprog(z, A, b, Aeq, beq, LB, UB)