Use of MATLAB optimization function linprog

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.