MATLAB is really strong, and the optimization is much more convenient.
Let's talk about the use of linprog first:
Min f'x
Constraint: ax <= B
Equality Constraints: aeqx = beq
LB <= x <= UB
The call format of the linprog function is as follows:
In linprog, F is the minimum value. Remember this. A and B are parameters of inequality constraints.
Aeq and beq are parameters of Equality Constraints
LB and UB are values of X.
Function usage:
X = linprog (F, a, B) x = linprog (F, a, B, aeq, beq) x = linprog (F, a, B, aeq, beq, LB, UB) x = linprog (F, a, B, aeq, beq, LB, UB, X0) x = linprog (F, a, B, aeq, beq, LB, UB, x0, options) [x, fval] = linprog (...) [X, fval, exitflag] = linprog (...) [X, fval, exitflag, output] = linprog (...) [X, fval, exitflag, output, Lambda] = linprog (...)
It is generally used as follows:
X = linprog (F, a, B, AEP, beq, LB, UB );
The main note in setting is whether the dimension of the parameter corresponds to the used dimension.
For example:
The most commonly used products in life: assume there are three types of products, A, B, and C. The total number of three commodities cannot exceed 30; the number of commodities in C cannot exceed 15, and the number of commodities in B cannot exceed 10.
The unit price is 10, 20, 30. The number of each of the three commodities is the highest and the sales volume is the highest.
Transformed into a mathematical problem:
Condition:
A + B + C <30
C <15
B <10
Function: F = 10 * A + 20 * B + 30 * C
Because linprog calculates the minimum value, we change it to: F =-(10 * A + 20 * B + 30 * C)
In this way, we have a function, and then:
According to the constraints, there are:
A = [1 1 1; 0 0 1; 0 1 0] B = [30 15 10]
However, the result can be a decimal or negative number.
Therefore, we add the upper and lower limits of a B C.
Lp = [0 0 0] Up = [30 30 30]
If you need to get the decimal result in the calculation, you only need to write it as 0.00 or 30.00.
Finally, we can bring it into function compute.
After writing this article, I found that the example is quite watery (self-edited). Please forgive me, the level is limited.