若某非线性规划的目标函数为自变量 x 的二次函数,约束条件又全是线性的,就称这种规划为二次规划。
m i n 1 2 x T H x + f T x s . t . A x ≤ b min \frac{1}{2}x^THx+f^Tx\\ s.t.\quad Ax \leq b min21xTHx+fTxs.t.Ax≤b
[ x , f v a l ] = q u a d p r o g ( H , f , A , b , A e q , b e q , L B , U B , X 0 ) [x,fval]=quadprog(H,f,A,b,Aeq,beq,LB,UB,X0) [x,fval]=quadprog(H,f,A,b,Aeq,beq,LB,UB,X0)
m i n f ( x ) = 2 x 1 2 − 4 x 1 x 2 + 4 x 2 2 − 6 x 1 − 3 x 2 s . t . { x 1 + x 2 ≤ 3 4 x 1 + x 2 ≤ 9 x 1 , x 2 ≥ 0 minf(x)=2x_1^2-4x_1x_2+4x_2^2-6x_1-3x_2\\ s.t.\begin{cases} x_1+x_2 \leq3\\ 4x_1+x_2\leq 9\\ x_1,x_2\geq 0 \end{cases} minf(x)=2x12−4x1x2+4x22−6x1−3x2s.t.⎩⎪⎨⎪⎧x1+x2≤34x1+x2≤9x1,x2≥0
h = [4,-4;-4,8];
f = [-6;-3];
a = [1,1;4,1];
b = [3;9];
[x,fval] = quadprog(h,f,a,b,[],[],zeros(2,1));
disp(x)
disp(fval)
规划中的变量限制为整数时,称为整数规划。
[ x , f v a l ] = i n t l i n p o g ( c , i n t c o n , A , b , A e q , b e q , L B , U B ) [x,fval]=intlinpog(c,intcon,A,b,Aeq,beq,LB,UB) [x,fval]=intlinpog(c,intcon,A,b,Aeq,beq,LB,UB)
m i n z = − 3 x 1 − 2 x 2 − x 3 s . t . { x 3 i n t x 1 , x 2 ≥ 0 x 1 + x 2 + x 3 ≤ 7 4 x 1 + 2 x 2 + x 3 = 12 minz=-3x_1-2x_2-x_3\\ s.t.\begin{cases} x_3 \quad int\\ x_1,x_2 \geq 0\\ x_1+x_2+x_3 \leq 7\\ 4x_1+2x_2+x_3 = 12 \end{cases} minz=−3x1−2x2−x3s.t.⎩⎪⎪⎪⎨⎪⎪⎪⎧x3intx1,x2≥0x1+x2+x3≤74x1+2x2+x3=12
clear
c = [-3;-2;-1];
intcon = 3;
A = [1 1 1];
b = 7;
Aeq = [4 2 1];
beq = 12;
[x,fval] = intlinprog(c,intcon,A,b,Aeq,beq,[0;0;0]);
disp(x)
disp(fval);