优化方法Word格式.docx
- 文档编号:21879874
- 上传时间:2023-02-01
- 格式:DOCX
- 页数:31
- 大小:19.60KB
优化方法Word格式.docx
《优化方法Word格式.docx》由会员分享,可在线阅读,更多相关《优化方法Word格式.docx(31页珍藏版)》请在冰豆网上搜索。
slope=dot(gk,dk);
whilef1>
f0+0.1*ak*slope
ak=ak/2;
xk=x0+ak*dk;
f1=fun(xk);
end
k=k+1;
x0=xk;
gk=grad(xk);
fprintf('
--The%d-thiter,theresidualis%f\n'
k,res);
x_star=xk;
functionf=fun(x)
f=(1-x
(1))^2+100*(x
(2)-x
(1)^2)^2;
functiong=grad(x)
g=zeros(2,1);
g
(1)=2*(x
(1)-1)+400*x
(1)*(x
(1)^2-x
(2));
g
(2)=200*(x
(2)-x
(1)^2);
运行结果:
>
x0=[0,0]'
;
eps=1e-4eps=
1.0000e-004
xk=steepest(x0,eps)
--The1-thiter,theresidualis3.271712
--The2-thiter,theresidualis2.504194
--The3-thiter,theresidualis2.073282
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
--The998-thiter,theresidualis0.449447
--The999-thiter,theresidualis0.449447
--The1000-thiter,theresidualis0.449447
--The1001-thiter,theresidualis0.449447
xk=
0.6369
0.4038
2.牛顿法
functionx_star=newton(x0,eps)
bk=[grad2(x0)]^(-1);
dk=-bk*gk;
xk=x0+dk;
bk=[grad2(xk)]^(-1);
functiong=grad2(x)
g=zeros(2,2);
g(1,1)=2+400*(3*x
(1)^2-x
(2));
g(1,2)=-400*x
(1);
g(2,1)=-400*x
(1);
g(2,2)=200;
eps=1e-4;
xk=newton(x0,eps)
--The1-thiter,theresidualis447.213595
--The2-thiter,theresidualis0.000000
1.0000
3.BFGS方法
functionx_star=bfgs(x0,eps)
g0=grad(x0);
gk=g0;
Hk=eye
(2);
dk=-Hk*gk;
fa0=xk-x0;
g0=gk;
y0=gk-g0;
Hk=((eye
(2)-fa0*(y0)'
)/((fa0)'
*(y0)))*((eye
(2)-
(y0)*(fa0)'
*(y0)))+(fa0*(fa0)'
*(y0));
functionf=fun(x)
f=(1-x
(1))^2+100*(x
(2)-x
(1)^2)^2;
>
xk=bfgs(x0,eps)
--The2-thiter,theresidualis2.381565
--The3-thiter,theresidualis3.448742
--The998-thiter,theresidualis0.004690
--The999-thiter,theresidualis0.008407
--The1000-thiter,theresidualis0.005314
--The1001-thiter,theresidualis0.010880
0.9955
0.9911
4.共轭梯度法
functionx_star=conj(x0,eps)
d0=dk;
k=k+1;
x0=xk;
gk=grad(xk);
f=(norm(gk)/norm(g0))^2;
res=norm(gk);
dk=-gk+f*d0;
f=(1-x
(1))^2+100*(x
(2)-x
(1)^2)^2;
functiong=grad(x)
g=zeros(2,1);
g
(1)=400*x
(1)^3-400*x
(1)*x
(2)+2*x
(1)-2;
g
(2)=-200*x
(1)^2+200*x
(2);
xk=Conj(x0,eps)
--The2-thiter,theresidualis1.380542
--The3-thiter,theresidualis4.527780
--The4-thiter,theresidualis0.850596
⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
--The73-thiter,theresidualis0.001532
--The74-thiter,theresidualis0.000402
--The75-thiter,theresidualis0.000134
--The76-thiter,theresidualis0.000057
0.9999
上机大作业Ⅱ:
编写程序利用增广拉格朗日方法求解下述问题
min4x1-x2-12
22
s.t.25-x1-x2=0
10x1–x1+10x2-x2-34≥0
x,x
≥0
初始点取x
0=0,精度取ε=1e-4.
主程序:
function[x,mu,lamda,output]=main(fun,hf,gf,dfun,dhf,dgf,x0)
maxk=2000;
theta=0.8;
eta=2.0;
k=0;
ink=0;
ep=1e-4;
sigma=0.4;
x=x0;
he=feval(hf,x);
gi=feval(gf,x);
n=length(x);
l=length(he);
m=length(gi);
mu=0.1*ones(l,1);
lamda=0.1*ones(m,1);
betak=10;
betaold=10;
while(betak>
ep&
maxk)
[ik,x,val]=bfgs('
lagrang'
'
dlagrang'
x0,fun,hf,gf,dfun,dhf,dgf,mu,lamda,sigma);
ink=ink+ik;
he=feval(hf,x);
betak=sqrt(norm(he,2)^2+norm(min(gi,lamda/sigma),2)^2);
ifbetak>
ep
mu=mu-sigma*he;
lamda=max(0.0,lamda-sigma*gi);
if(k>
=2&
betak>
theta*betaold)
sigma=eta*sigma;
betaold=betak;
x0=x;
f=feval(fun,x);
output.fval=f;
output.iter=k;
output.inner_iter=ink;
output.beta=betak;
增广拉格朗日函数
functionlag=lagrang(x,fun,hf,gf,dfun,dhf,dgf,mu,lamda,sigma)
l=length(he);
lag=f;
s1=0.0;
for(i=1:
l)
lag=lag-he(i)*mu(i);
s1=s1+he(i)^2;
lag=lag+0.5*sigma*s1;
s2=0.0;
m)
s3=max(0.0,lamda(i)-sigma*gi(i));
s2=s2+s3^2-lamda(i)^2;
lag=lag+s2/(2.0*sigma);
增广拉格朗日梯度函数
functiondlag=dlagrang(x,fun,hf,gf,dfun,dhf,dgf,mu,lamda,sigma)
dlag=feval(dfun,x);
dhe=feval(dhf,x);
dgi=feval(dgf,x);
dlag=dlag+(sigma*he(i)-mu(i))*dhe(:
i);
dlag=dlag+(sigma*gi(i)-lamda(i))*dgi(:
线搜索程序基于BFGS方法
function[k,x,val]=bfgs(fun,gfun,x0,varargin)
Max=1000;
ep=1.e-4;
beta=0.55;
sigma1=0.4;
n=length(x0);
Bk=eye(n);
while(k<
Max)
gk=feval(gfun,x0,varargin{:
});
if(norm(gk)<
ep),break;
end
dk=-Bk\gk;
m=0;
mk=0;
while(m<
20)
newf=feval(fun,x0+beta^m*dk,varargin{:
oldf=feval(fun,x0,varargin{:
if(newf<
=oldf+sigma1*beta^m*gk'
*dk)
mk=m;
break;
m=m+1;
x=x0+beta^mk*dk;
sk=x-x0;
yk=feval(gfun,x,varargin{:
})-gk;
if(yk'
*sk>
0)
Bk=Bk-(Bk*sk*sk'
*Bk)/(sk'
*Bk*sk)+(yk*yk'
)/(yk'
*sk);
val=feval(fun,x0,varargin{:
目标函数文件
functionf=f1(x)
f=4*x
(1)-x
(2)^2-12;
等式约束文件
functionhe=h1(x)
he=25-x
(1)^2-x
(2)^2;
不等式约束
functiongi=g1(x)
gi=zeros(3,1);
gi
(1)=10*x
(1)-x
(1)^2+10*x
(2)-x
(2)^2-34;
gi
(2)=x
(1);
gi(3)=x
(2);
目标函数梯度文件
functiong=df1(x)
g=[4;
-2*x
(1)];
等式函数梯度文件
functiondhe=dh1(x)
dhe=[-2*x
(1);
-2*x
(2)];
不等式函数梯度文件
functiondgi=dg1(x)
dgi=[10-2*x
(1),1,0
;
10-2*x
(2)
,0,1];
输入数据
X0=[0;
0]
[x,mu,lamda,output]=main('
f1'
'
h1'
g1'
df1'
dh1'
dg1'
x0)
输出数据
x=
1.0013
4.8987
mu=
0.0158
lamda=
0.5542
output=
fval:
-31.9924
iter:
5
inner_iter:
33
beta:
8.4937e-005
上机大作业Ⅲ:
1.解:
将目标函数改写为向量形式:
x'
*a*x-b*x
程序代码:
n=2;
a=[0.5,0;
0,1];
b=[24];
c=[11];
cvx_begin
variablex(n)
minimize(x'
*a*x-b*x)
subjectto
c*x<
=1
x>
=0
cvx_end
运算结果:
CallingSDPT34.0:
7variables,3equalityconstraints
Forimprovedefficiency,SDPT3issolvingthedualproblem.
------------------------------------------------------------
num.ofconstraints=3
dim.ofsocpvar=4,num.ofsocpblk=1
dim.oflinearvar=3
*******************************************************************
SDPT3:
Infeasiblepath-followingalgorithms
versionpredcorrgamexponscale_data
NT
10.000
itpstepdsteppinfeasdinfeasgap
prim-obj
dual-obj
cputime
-------------------------------------------------------------------
0|0.000|0.000|8.0e-001|6.5e+000|3.1e+002|1.000000e+0010.000000e+000|0:
0:
00|chol11
1|1.000|0.987|4.3e-007|1.5e-001|1.6e+001|9.043148e+000-2.714056e-001|0:
01|chol11
2|1.000|1.000|2.6e-007|7.6e-003|1.4e+000|1.234938e+000-5.011630e-002|0:
3|1.000|1.000|2.4e-007|7.6e-004|3.0e-001|4.166959e-0011.181563e-001|0:
4|0.892|0.877|6.4e-008|1.6e-004|5.2e-002|2.773022e-0012.265122e-001|0:
5|1.000|1.000|1.0e-008|7.6e-006|1.5e-002|2.579468e-0012.427203e-001|0:
6|0.905|0.904|3.1e-009|1.4e-006|2.3e-003|2.511936e-0012.488619e-001|0:
7|1.000|1.000|6.1e-009|7.7e-008|6.6e-004|2.503336e-0012.496718e-001|0:
8|0.903|0.903|1.8e-009|1.5e-008|1.0e-004|2.500507e-0012.499497e-001|0:
9|1.000|1.000|4.9e-010|3.5e-010|2.9e-005|2.500143e-0012.499857e-001|0:
10|0.904|0.904|5.7e-011|1.3e-010|4.4e-006|2.500022e-0012.499978e-001|0:
01|chol22
11|1.000|1.000|5.2e-013|1.1e-0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 优化 方法
![提示](https://static.bdocx.com/images/bang_tan.gif)