Linear programming functions in Matlab

Source: Internet
Author: User
Tags constant

Linear programming
LP (Linear programming, linear programming) is an optimization method in which both the objective function and the constraint function are linear functions of the vector variable, and the LP problem can be described as:
Min x
S.T.
A x B
Aeq x=beq
VLB x vub
Where b,beq are vectors, A,aeq are matrices, and x is vector variables. Matrices A and B are coefficients of linear inequality constraints, and Aeq and beq are coefficients of equality constraints.
In MATLAB, the solution function for LP is LINPROG. Its invocation format is:
[X,fval,lambda]=linprog
(f,a,b,aeq,beq,vlb,vub,x0,options)
Where F,a,b, is not the default input variable, x is not the default output variable, it is the solution of the problem. Vlb,vub are vectors that represent the lower and upper bounds of X, x0 the starting point of X, and options as the value of the parameter defined in the Optimset function, fval is the target letter
Number at the value at the solution x, The lambda is the Lagrange multiplier at the solution x. lambda.lower corresponds to vlb,lambda.upper corresponding to a linear inequality constraint, and lambda.eqlin corresponds to a linear equality constraint. .

Here's a small example of how the function works:

minz=-4a+b+7c

S.T.

A+b-c=5 3a-b+c<=4

A+b-4c<=-7 a,b>=0

Q A,b,c What values are taken separately, Z has a minimum value

Writing m files

C=[-4 1 7];

A=[3-1 1;1 1-4];

B=[4;-7];

Aeq=[1 1-1];

beq=[5];vlb=[0, 0];

Vub=[]; [X,fval]=linprog (C,a,b,aeq,beq,vlb,vub)

Result: x = 2.2500 6.7500 4.0000fval = 25.7500

That is, when the a,b,c is 2.2500 6.7500 4.0000, Z has a minimum value of 25.7500

A more detailed example is as follows, as the difference between the maximum and minimum values is not stated above, supplemented as follows:

function Format : Linprog (f,a,b,a1,b1,xstart,xend)

F: the expression coefficient matrix that solves the minimum function is the matrix of the M*1

The conditional constraint matrix of a:≤ inequality is all form

B:A constant term to the right of the corresponding inequality

a1:= equation Conditional constraint matrix

B1:A1 constant term to the right of the corresponding inequality

A matrix of n*1 for the minimum value of the value range of the Xstart:x

A matrix of n*1 for the maximum value of the xend:x range of values

function Description : The item that does not exist is filled in [].

function function : Linear programming to find the optimal value.

Example 1:

Find the maximum value of f=3*x1+6*x2+2*x3

The conditions to be met are

3*x1+4*x2+x3≤2

X1+3*x2+2*x3≤1

and X1, x2, X3 are greater than or equal to 0

MATLAB solution is as follows

A =[3 4 1

1 3 2]

b =[2

1]

f=[-3

-6

-2]% Why this is a negative number, because MATLAB is to ask for the minimum value of F, the maximum is required to take the inverse of the requirement coefficient can be.

x=[0

0

0]

Linprog (f,a,b,[],[],x,[])% executes the MATLAB command after the output of the following content. Note that [] here means that the item does not exist. Of course the last one [] also can not be the Linprog (f,a,b,[],[],x)

Optimization terminated.

Ans =

0.4000

0.2000

0% is the optimal solution for x1=0.4,x2=0.2,x3=0. Bring back the original I can know the maximum value of f =3*0.4+6*0.2=2.4

Example 2:

To find the minimum value of f=-2*x1-3*x2-x3

The conditions to be met are

X1+x2+x3≤3

X1+4*x2+7*x3+x4=9

and X1, x2, x3, X4 are all greater than or equal to 0

MATLAB solution is as follows

The original problem is equivalent to finding the minimum value of f=-2*x1-3*x2-x3+0*x4

The condition is equivalent to

X1+x2+x3+0*x4≤3

X1+4*x2+7*x3+x4=9

Then enter the following in MATLAB

A=[1 1 1 0]

B=[3]

A1=[1 4 7 1]

B1=[9]

x=[0

0

0

0]

f=[-2

-3

-1

0]

Linprog (f,a,b,a1,b1,x)% execute command or input Linprog (f,a,b,a1,b1,x,[])

Optimization terminated.

Ans =

1.0000

2.0000

0.0000

0% description x1=1,x2=2,x3=0,x4=0 Get minimum value

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.