Solving Linear Programming Problems with MATLAB
Overview
You can use the Optimization Toolbox
1. Insert the in matrix form for the linear programming problem.
Code
As a simple example, let’s solve the following maximization problem from . At the shrimp sushi restaurant, this problem was solved manually using the simplex method, and the answer was known. This linear programming problem is
In such a form, since , , , it can be transcribed and solved as follows.
>> A = [-1 1
1 0
0 1];
b = [1 3 2];
c = [-1 -1];
x = linprog(f,A,b,[],[], [0,0])
Here, the reason for using c = [-1,-1]
instead of c = [1,1]
is because the basic optimization direction of linprog()
is for minimization. Just reversing that direction is tantamount to maximization, and the result is [3 2]
, as we already knew.
최적해를 구했습니다.
x =
3
2
Environment
- OS: Windows
- MATLAB: v9.9.0.1592791 (R2020b)
- Optimization Toolbox: v9.0 (R2020b)