最优控制及最优化实验
姓名:李佳乐
学号:40950104
班级:电091 班
学院:自动化学院
同组:张蕾陈瑜
1
实验一:线性规划
实验目的:要求学生能用 Matlab Optimization Toolbox求解线性规划问题。 实验内容:练习使用 linprog求解线性规划问题。
【练习1】将例1 中的最优化问题的前三个不等式约束变为等式约束(如下所示),重新求解, 判断解的存在性。(注:需要调用
[x,fval,exitflag,output,lambda] =linprog(...),通过exitflag的值判断解的存在性)
min?5x1?4x2?6x3
s..tx1?x2?x3?20
3x1?2x2?4x3?42
3x1?2x2?30
x1,x2,x3?0
程序:
f=[-5;-4;-6];
A=[];b=[];
Aeq=[1,-1,1;3,2,4;3,2,0];
beq=[20;42;30];
lb=zeros(3,1);
[x,fval,exitflag,output,lambda]=linprog(f,A,b,Aeq,beq,lb,[])
结果:
Exiting: One or more of the residuals, duality gap, or total relative error
has grown 100000 times greater than its minimum value so far:
the primal appears to be infeasible (and the dual unbounded).
(The dual residual < TolFun=1.00e-008.)
x =
16.3148
0.0000
6.9098
fval =
-123.0326
exitflag =
2
-2
output =
iterations: 4
algorithm: 'large-scale: interior point'
cgiterations: 0
message: [1x258 char]
lambda =
ineqlin: [0x1 double]
eqlin: [3x1 double]
upper: [3x1 double]
lower: [3x1 double]
因为exitflag = -2<0,所以没有解。
【练习2】建一个.m文件,求解下面的线性规划问题。
min?2x1?x2?4x3?3x4?x5
s..2tx2?x3?4x4?2x5?54
3x1?4x2?5x3?x4?x5?62
x1,x2?0,x3?3.32,x4?0.678,x5?2.57
程序:
f=[-2;-1;-4;-3;-1];
A=[0 2 1 4 2;3 4 5 -1 -1];
b=[54;62];
Aeq=[];
beq=[];
lb=[0;0;3.32;0.678;2.57];
[x,fval,exitflag,output,lambda]=linprog(f,A,b,Aeq,beq,lb,[])
结果:
Optimization terminated.
x =
19.7850
0.0000
3.3200
11.3850
2.5700
3
fval =
-89.5750
exitflag =
1
output =
iterations: 6
algorithm: 'large-scale: interior point' cgiterations: 0
message: 'Optimization terminated.'
lambda =
ineqlin: [2x1 double]
eqlin: [0x1 double]
upper: [5x1 double]
lower: [5x1 double]
exitflag =1>0,所以收敛为一个解。 4 因为
实验二:二次规划问题的求解
实验目的:要求学生能用 Optimization toolbox求解二次规划问题。 实验内容:使用quadprog()函数求解二次规划问题
min1xTHx?fT
2x
二次规划问题的数学表示为:
s..tAx?b
Aeqx?beq
lb?x?ub
调用格式:
x = quadprog(H,f,A,b)
x = quadprog(H,f,A,b,Aeq,beq)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub)
[x,fval] = quadprog(...)
[x,fval,exitflag,output,lambda] = quadprog(...)
【练习3】试求解下面的二次规划问题
min(x22
1?1)?(x2?2)2?(x3?3)2?(x4?4)
s..tx1?x2?x3?x4?5
3x
1?3x2?2x3?x4?10
x1,x2,x3,x4?0
程序:
H=diag([1 1 1 1]);
f=[-2;-4;-6;-8];
A=[1,1,1,1;3,3,2,1];
b=[5,10];
lb=zeros(4,1);
[x,fval,exitflag,output,lambda]=quadprog(H,f,A,b)
结果:
x =
-1.7500
0.2500
2.2500
4.2500
fval =
5
-31.8750
exitflag =
1
output =
iterations: 2
algorithm: 'medium-scale: active-set' firstorderopt: []
cgiterations: []
message: 'Optimization terminated.'
lambda =
lower: [4x1 double]
upper: [4x1 double]
eqlin: [0x1 double]
ineqlin: [2x1 double]
exitflag =1>0,所以收敛为一个解。 6 因为
实验三:用加权法求解多目标优化问题
实验目的:掌握用加权法求解多目标优化问题
实验内容:用加权法解多目标线性优化问题min Cx st. Ax>=b,即最小化两个目
标函数 1 1 2 f (x) = 3x + x 和2 1 2 f (x) = ?x ? 2x st. Ax >=b。
实验方法 : 使用加权法思想,将两个目标的优化问题转换成一个目标的优化问
题。分别设置两个目标的权重为w1 和w2, 将两个目标加权
w1f1(x)+w2f(x),然后优化。即minw1f1(x)+w2f(x) st. Ax>=b. 通
过取不同的权重,可以得到多个解。令1>=w1,w2>=0, w2=1-w1, 分
别取w1=0,0.2,0.4,0.6,0.8,1求解w1f1(x)+w2f(x),给出最优
解,并计算出两个目标函数的值。
程序:
for W1=0:0.2:1
W2=1-W1
f=[3*W1-W2;W1-2*W2];
A=[0 -1;-3 1;1 0;0 1];
b=[-3;-6;0;0];
[x,fval]=linprog(f,A,b,[],[],[],[])
[x,fval,exitflag,output,lambda] =linprog(f,A,b,[],[],[],[]);
f1=[3 1]*x
f2=[-1 -2]*x
end
运行结果:
W2 =
1
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
x =
3.7982
1.3663
7
fval =
-6.5308
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
f1 =
12.7609
f2 =
-6.5308
W2 =
0.8000
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
x =
1.7031
1.0469
fval =
-1.8063
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
8
and the primal objective > -1e+6.
f1 =
6.1563
f2 =
-3.7969
W2 =
0.6000
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
x =
2.1537
1.1969
fval =
0.3347
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
f1 =
7.6582
f2 =
9
-4.5476
W2 =
0.4000
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
x =
-0.1104
-6.3251
fval =
1.1105
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
f1 =
-6.6562
f2 =
12.7605
W2 =
0.2000
10
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
x =
0.4425
-4.2035
fval =
-0.7079
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
the primal appears to be infeasible and the dual unbounded since the dual objective > 1e+10
and the primal objective > -1e+6.
f1 =
-2.8760
f2 =
7.9646
W2 =
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
both the primal and the dual appear to be infeasible.
x =
0.4557
11
-12.2588
fval =
-10.8917
Exiting: One or more of the residuals, duality gap, or total relative error has stalled:
both the primal and the dual appear to be infeasible.
f1 =
-10.8917
f2 =
24.0619
>>
12
实验四:用支持向量机方法实现数据分类
训练数据:下面的数据为DNA 分类数据(共10 个),其中前面5个数据为第一 类,后面5为第二类。
0.29729731 0.13513514 ;
0.27027027 0.15315315 ;
0.27027027 0.06306306 ;
0.42342342 0.28828829 ;
0.23423424 0.10810811 ;
0.35454544 0.50000000 ;
0.32727272 0.50000000 ;
0.25454546 0.51818180 ;
0.30000000 0.50000000 ;
0.29090910 0.64545456 ;
未知分类信息的数据
0.35135136 0.12612613;
0.35135136 0.18918919;
0.27927927 0.18918919;
0.20909090 0.15454545;
0.18181818 0.13636364;
0.36363636 0.46363636;
0.35454544 0.26363636;
0.29090910 0.50000000;
0.21818182 0.56363636;
0.20000000 0.56363636;
要求:(1)画出训练集数据点,其中第一类用“o”表示,第二类用“*”来表 示。(2)求解二次规划问题,给出分类超平面的参数w,b并在图中画出分类超 平面(可画一段线段)。(3)对未知数据进行分类,分类结果需在图中展现。 属于第一类的请用实心的“.”来表示,属于第二类的请用“+”来表示。(4) 给出全部程序代码。
程序:
x1=[0.29729731 0.27027027 0.27027027 0.42342342 0.23423424];
y1=[0.13513514 0.15315315 0.06306306 0.28828829 0.10810811];
x2=[0.35454544 0.32727272 0.25454546 0.30000000 0.29090910];
y2=[0.50000000 0.50000000 0.51818180 0.50000000 0.64545456];
plot(x1,y1,'o')
hold on
13
plot(x2,y2,'*')
H=[1 0 0;0 1 0;0 0 0];
A=[-0.29729731 -0.13513514 -1;-0.27027027 -0.15315315 -1;-0.27027027 -0.06306306 -1;-0.42342342 -0.28828829 -1;-0.23423424 -0.10810811 -1;0.35454544 0.50000000 1;0.32727272 0.50000000 1;0.25454546 0.51818180 1;0.30000000 0.50000000
1;0.29090910 0.64545456 1];
b=[-1;-1;-1;-1;-1;-1;-1;-1;-1;-1];
[x,fval]=quadprog(H,[],A,b,[],[],[],[])
hold on
x=0:1;
plot(x,(2.7792*x+2.2859)/8.5429,'y' )
hold on
plot(x,(2.7792*x+3.2859)/8.5429 )
hold on
plot(x,(2.7792*x+1.2859)/8.5429 )
w=[2.7792;-8.5426];
x2=[0.35135136 0.35135136 0.27927927 0.20909090 0.18181818 0.36363636 0.35454544 0.29090910 0.21818182 0.20000000];
y2=[0.12612613 0.18918919 0.18918919 0.15454545 0.13636364 0.46363636 0.26363636 0.50000000 0.56363636 0.56363636];
for n=1:10;
if([x2(n) y2(n)]*w+2.2859) >= 0;
hold on
plot(x2(n),y2(n),'g.')
else
hold on
plot(x2(n),y2(n),'g+')
end
end
14
结果: x =
2.7792 -8.5426
2.2859
fval =
40.3502
15
seo优化报告当我们接到单子总是找不到好的优化报告模板下面提供一份给大家接到某些网站负责人站长咨询网站营销遇到的一些问题我们根据询…
系统优化报告备注建议使用视图方式文档结构视图一总体对比二优化方法1硬件操作系统2网络环境3应用服务器124数据库服务器5应用程序2…
网站优化分析报告一整体测试与分析利用网络工具分析网站域名得到结果上图为综合查询分析结果以下我会一一进行分析1百度排名在这里可以清楚…
旅途旅游网优化分析报告报告分析人邓然分析网站旅途旅游网网站URL域名年龄3年9个月创建于20xx年10月26日优化关键词无锡旅行社…
结构优化报告一普通多层17222324252627二花庭美墅151618192021三高层部分3940414243四学校zzzz外…
富川县城现场RF优化报告3月10日3月11日对富川县城进行了现场RF优化并对县城区主要道路进行了DT复测重点对基站远点处信号质量覆…
毕业设计论文开题报告系别电子信息工程系专业通信工程班级学生姓名学号指导教师报告日期3月22日毕业设计论文开题报告表注内容用小四宋体
旅途旅游网优化分析报告报告分析人邓然分析网站旅途旅游网网站URL域名年龄3年9个月创建于20xx年10月26日优化关键词无锡旅行社…
网站优化分析报告一整体测试与分析利用网络工具分析网站域名得到结果上图为综合查询分析结果以下我会一一进行分析1百度排名在这里可以清楚…
华北科技学院管理系实验报告册实验报告实验时间20xx年12月20日关键词新闻凤凰网凤凰网是一个集图文资讯视频点播专题报道虚拟社区免…