Linear programming of MATLAB notes

Source: Internet
Author: User

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,

Aeq and beq are equations.

Constraint conditions

The coefficients.

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. .
Example 1
>>%solve the following linear programming problems% Max z=2x1+3x2-5x3% S.T. x1+x2+x3=7% 2x1-5x2+x3>=Ten% x1+3x2+x3<= A% x1,x2,x3>=0F=[2;3;-5];%target function column matrix A=[-2,5,-1;1,3,1];%Unequal matrix B=[-Ten; A]; Aeq=[1,1,1];%Equality Matrix BEQ=7; x=linprog (-f,a,b,aeq,beq,zeros (3,1)); %Zeros (m,n) produces a double class 0 matrix of MXN, zeros (n) produces nxn of all 0 squares of value=f'*x% The target value, which equals the value of [X,y]=linprog (-f,a,b,aeq,beq,zeros (3,1))-yoptimization Terminated.value=14.5714>>xx=6.4286     0.5714     0.0000>>
Example 2
>>%solve the following linear programming problems% min z=2x1+3x2+X3% S.T. x1+4x2+2x3>=8% 3x1+2x2>=6% x1,x2,x3>=0F=[2;3;1]; A=[-1,-4,-2;-3,-2,0]; b=[-8;-6]; X=linprog (F,a,b,[],[],zeros (3,1))%no equation, use [] instead of value=f'*x% whose value equals [X,y]=linprog (F,a,b,[],[],zeros (3,1)) yoptimization terminated.x=0.8066     1.7900     0.0166value=7.0000>>
Example 3
% min z=|x1|+2|x2|+3|x3|+4|x4|;% S.T. x1-x2-x3+x4=0;% x1-x2+x3-3*x4=1;% x1-x2-2*x3+3*x4=-0.5%objective function Objfun[Email protected] (x) ABS (X (1))+2*abs (X (2))+3*abs (X (3))+4*abs (X (4)) %Equality constraint Aeq=[1-1-1 1      1-1 1–3      1-1-2 3]; BEQ=[0 1-0.5]'; x0=[0 0 0 0];%It's critical and important to give an initial value oh x=fmincon (OBJFUN,X0,[],[],AEQ,BEQ)%Below is a program based on the need to improve min Z=[1 2 3 4 1 2 3 4]*[U1 U2 U3 U4 v1 v2 v3 v4]'s.t.a=[1-1-1 1 1-1-1 1   1-1 1-3 1-1 1–3   1-1-2 3 1-1-2 3]x=[U1 U2 U3 U4 v1 v2 v3 v4]'b=[0 1-0.5]'Ax=BX>=0%objective function F=[1 2 3 4 1 2 3 4];%Equality constraint Aeq=[1-1-1 1 1-1-1 1     1-1 1-3 1-1 1–3     1-1-2 3 1-1-2 3];beq=[0 1-0.5]';%Boundary condition LB=zeros (8,1);%Call LINPROGX=Linprog (f,[],[],aeq,beq,lb) optimization terminated.x=0.2500    0.0000    0.2500    0.0000    0.2500    0.0000    0.2500    0.0000

Linear programming of MATLAB notes

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.