二次规划实验举例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
最优化算法实验指导书
2.二次规划求解
例1 求解下面二次规划问题
21212221x 6x 2x x x x 2
1)x (f min
---+= sub.to 2x x 21≤+
2x 2x 21≤+-
3x x 221≤+
21x 0,x 0≤≤ 解:x f x H x 2
1)x (f '+'= 则⎥⎦⎤⎢⎣⎡--=2111H ,⎥⎦
⎤⎢⎣⎡--=62f ,⎥⎦⎤⎢⎣⎡=21x x x 在MA TLAB 中实现如下:
>> H = [1 -1; -1 2] ;
>> f = [-2,-6];
>> A = [1 1; -1 2; 2 1];
>> b = [2; 2; 3];
>> lb = zeros(2,1);
>> [x,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[ ],[ ],lb)
Warning: Large-scale method does not currently solve this problem formulation, switching to medium-scale method.
> In C:\MATLAB6p5\toolbox\optim\quadprog.m at line 213
Optimization terminated successfully.
x =
0.6667
1.3333
fval =
-8.2222
exitflag =
1
output =
iterations: 3
algorithm: 'medium-scale: active-set'
firstorderopt: []
cgiterations: []
lambda =
lower: [2x1 double]
upper: [2x1 double]
eqlin: [0x1 double]
ineqlin: [3x1 double]
例 1123 2212123min 246y x x x x x =+---
..s t 1232131232
3
4
,,0x x x x x x x x x +≤+≤+≤≥
(1)标准形式:
由 2212123246y x x x x x =+---
22121231(22)2462
x x x x x =+--- 知 200020000H ⎛⎫ ⎪= ⎪ ⎪⎝⎭
为半正定矩阵,约束不必改动。
(2)在编辑窗口建立一个存放各种信息的M 文件,
在MA TLAB 中实现如下:
>> H = [2 0 0;0 2 0;0 0 0];
>> f = [-2 -4 -6];
>> A = [1 1 0; 0 1 1; 1 0 1];
>> b = [2; 3; 4];
>> C =[];
>> d=[];
>> xm=[0; 0; 0];
>> xM=[];
>> x0=[0,0,0];
>> [x,y]=quadprog(H,f,A,b,C,d,xm,xM,x0)
Warning: Large-scale method does not currently solve this problem formulation, switching to medium-scale method.
> In C:\MATLAB6p5\toolbox\optim\quadprog.m at line 213
Optimization terminated successfully.
x =
1.0000
0.0000
3.0000
y =
-19
例1124 22212131123min ()()246y x x x x x x x x =+++----
..s t 1232131231232
3
4 3.5
,,0
x x x x x x x x x x x x +≤+≤+≤++=≥
(1)标准形式:
由 2221231213123
22246y x x x x x x x x x x =++++--- 22212312131231(22244)2462
x x x x x x x x x x =++++--- 知 222220202H ⎛⎫ ⎪= ⎪ ⎪⎝⎭
为不定矩阵,约束不必改动。
(2)在编辑窗口建立一个存放各种信息的M 文件,
在MA TLAB 中实现如下:
>> H = [2 2 2;2 2 0;2 0 2];
>> f = [-2 -4 -6];
>> A = [1 1 0; 0 1 1; 1 0 1];
>> b = [2; 3; 4];
>> C=[1 1 1];
>> d=[3.5];
>> xm=[0; 0; 0];
>> xM=[];
>> [x,y]=quadprog(H,f,A,b,C,d,xm,xM,x0)
Warning: Large-scale method does not currently solve this problem formulation, switching to medium-scale method.
> In C:\MATLAB6p5\toolbox\optim\quadprog.m at line 213
Optimization terminated successfully.
x =
0.5000
1.0000
2.0000
y =
-8.7500
作业布置:5.11 5.12