一维优化方法总结
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一维优化方法总结
第三章:一维优化方法总结
1.一维优化方法介绍
求解以为目标函数f (x )最优解的过程,称为一维优化,所使用的方法称为一维优化方法。
一维优化方法是优化方法中最简单、最基本的优化方法。
他不仅用来解决一维目标函数的求最优问题,而且常用于多维优化问题在既定方向上寻求最优步长的一维搜索。
对于任一次迭代计算,总是希望从已知的点()k x 出发,沿给定的方向()k s 搜索该方向上到目标函数值最小的点(1)k +x 。
这种在确定的搜索方向()k s 上按步长因子
()k α迭代使得目标函数在该方向上达到极小值的过程称为一维搜索优化计算方
法。
一维搜索最优化方法一般需要分两步进行:第一步是在()k s 方向上确定使得目标函数值取得最小值的步长因子()k α所在的区间;第二步是采用不同方法利用步长因子()k α求得近似解。
2.搜索区间的确定及matlab 编程
所谓搜索区间就是沿给定的搜索方向()k s 上找出一个单峰区间12[,]αα,即在该区间内目标函数值的变化只有一个峰值。
本文选用进退法进行区间确定。
这里直接以一维函数为例。
设函数为()y f x =,给定初始点1x ,选定恰当的步长为0h ,求其最小点*x 。
进退法分为三步:试探搜索、前进搜索和后退搜索。
第一步:试探搜索
由于最小点*x 的位置是未知的,所以首先要试探最小点*x 位于初始点1x 的左方还是右方,然后再确定包含*x 在内的搜索区间[,]a b 。
由初始点1x 沿Ox 轴正向到2x 点,210x x h =+,分别计算两点的函数值11()y f x =,
22()y f x =并比较1y 和2y 值的大小,可分为两种情况:
(1)若21y y <,则极小点必在点右方,应继续前进搜索;
(2)若21y y >,则极小点必在1x 点左方,应反向,即作后退搜索。
第二步:前进搜索
由探索后的2x 点,沿Ox 正向继续前进搜索。
令02h h =,取得前进方向的第三个点32x x h =+,对应的函数值33()y f x =,比较后两个点的函数值,有如下两种情况:
(1)若23y y <,则三个点123x x x 、、的函数值的关系为123y y y ><。
此时函数()f x 在13[,]x x 区间内必有极小点,于是令1a x =,3b x =从而构成了搜索区间[,]a b 。
(2)若23y y >,则应该继续向前搜索,令12122323,,,x x y y x x y y ====,再将步长倍增,即2h h =,构成新点并计算其函数值3233,x x h y x =+=。
比较2y 和3y 的值,若有23y y >则转(2),直到出现23y y <成立,转(1),确定搜索区间。
第三步:后退搜索
此时,需沿Ox 负方向搜索,因此令00h h =?,并将1x 和2x 点的位置调换,即令
3131
12122323
,,,x x y y x x y y x x y y ======进行这样的处理以后,后面的步骤和前进搜索的处理完全相同,只是最后确定搜索区间时,令31,a x b x ==。
Matlab 程序如下:
function [mina,maxb]=funab(f,xzero,hzero,eps)format long ;if nargin==3
eps=1e-6;end
x1=xzero;k=0;
h=hzero;while 1
x4=x1+h;k=k+1;
f4=subs(f,findsym(f),x4);
f1=subs(f,findsym(f),x1);if f4<f1< bdsfid="93" p=""></f1<> x2=x1;x1=x4;f2=f1;f1=f4;h=2*h;else
h=-h;x2=x4;f2=f4;else
x3=x2;x2=x1;x1=x4;break ;end end
end
mina=min(x1,x3);maxb=x1+x3-mina;format short ;
3.黄金分割法求极值的基本原理及matlab 编程
黄金分割法也称0.618法。
本方法是通过对分割点函数值进行比较来逐次缩短区间的,属于应用序列消去原理的直接探索法。
设有目标函数()f x ,给定初始搜索区间[,]a b ,收敛精度为ε。
首先,在初始搜索区间内取两个点1x 与2x ,12x x <且在区间内对称位置,两点对应的函数值分别为11()y f x =和22()y f x =,比较1y 与2y 的大小,有下面两种情况:
(1)若有12y y <,极小点必在区间2[,]a x 内,此时令2b x =,实现区间的一次缩短;
(2)若有12y y ≥,极小点必在区间1[,]x b 内,此时可令1a x =,缩短后的新区间为1[,]x b 。
经过多次用黄金分割法进行一维优化搜索,当满足迭代精度时即可停止计算,取最终收缩区间的中点为近似最优点,最优解为()()*0.5()*(*)
k k x a b f f x ?=+?
=?Matlab 程序如下:
function [x,fval,xzero]=fun618(a,b)xzero=0;
while abs(b-a)>1e-4
xzero=xzero+1;
lambda=a+0.382*(b-a);mid=a+0.618*(b-
a);[dy,f1]=funx(lambda);[dy,f2]=funx(mid);if f1>f2
a=lambda;
disp([made the new search area is:['num2str(a)','num2str(b) '].'])
else
disp(['the number'num2str(xzero)'iteration made the new
search area is:['num2str(a)','num2str(b)'].'])
end end
x=(a+b)/2;
[dy,fval]=funx(x);
4.算例
计算)2()(+=x x x f 的极小点。
解:首先在matlab 中输入:>>syms x;>>f=x*(x+2);>>[a,b]=funab(f,0,1);得到结果:>>a a =-3>>b
b=0
因此获得搜索区间[-3,0]。
然后进行黄金分割法计算。
编写程序:
function[dy,fval]=funx(x)
fval=x*(x+2);
dy=2*x+2;
end
然后输入:
[x,fval,xzero]=fun618(-3,0)
得到如下结果:
>>[x,fval,xzero]=fun618(-3,0)
the number1iteration made the new search area is:[-1.854,0].
the number2iteration made the new search area is:[-1.854,-
0.70823]. the number3iteration made the new search area is:[-
1.4163,-0.70823]. the number4iteration made the new search area is:[-1.1458,-0.70823]. the number5iteration made the new search area is:[-1.1458,-0.87539]. the number6iteration made the new search area is:[-1.0425,-0.87539]. the number7iteration made the new search area is:[-1.0425,-0.93923]. the
number8iteration made the new search area is:[-1.0425,-0.97869]. the number9iteration made the new search area is:[-1.0181,-
0.97869]. the number10iteration made the new search area is:[-
1.0181,-0.99376]. the number11iteration made the new search area is:[-1.0088,-0.99376]. the number12iteration made the new search area is:[-1.0031,-0.99376]. the number13iteration made the new search area is:[-1.0031,-0.99731]. the number14iteration made the new search area is:[-1.0009,-0.99731]. the number15iteration made the new search area is:[-1.0009,-
0.99867]. the number16iteration made the new search area is:[-
1.0009,-0.99951]. the number17iteration made the new search area is:[-1.0004,-0.99951]. the number18iteration made the new search area is:[-1.0004,-0.99983]. the number19iteration made the new search area is:[-1.0002,-0.99983]. the number20iteration made the new search area is:[-1.0002,-0.99996]. the number21iteration made the new search area is:[-1.0001,-0.99996]. the number22iteration made the new search area is:[-1,-0.99996].
x=
-1.0000
fval=
-1.0000
xzero =
22
即经过22次迭代,得到极小值点-1.0000。
极小值为-1.0000。
5.对算例提出的问题
通过手算该算例,很容易得到)2()(+=x x x f 的极小值为(-1,-1)。
但是通过迭代过程我们可以看到matlab 在接近极小值点附近时由于设置的精度过高(410?=ε)导致其需要反复迭代多次才能得到相应结果。
因此我认为在日常计算应用时因选用合适精度才能更有效率地得到适
当的近似解。
另外,在编制程序时还需要手动求得原函数的一阶导数并输入进funx (x )函数之中,比较麻烦。
我们可以利用dy=diff(f,x)函数来进行求解。
如下所示:
>>syms dy f x;>>f=x*(x+2);>>dy=diff(f,x);>>dy
dy =
2*x +2。