資源簡介
matlab_FR共軛梯度算法+BFGS擬牛頓算法
求解實(shí)例在funf.m中,我是手動求解的g,大家可以自動求。

代碼片段和文件信息
x_old?=?[100;100];
his_x?=?[x_old‘];
h_old?=?[10;01];
n_it=0;
err=1e-5;
f_old?=?funf(x_old);
his_f?=?[f_old];
nf=1;
maxn=3;
gf_old?=?gradf(x_old);
ngf=1;
resd?=?norm(gf_old);
his_ep=[resd];
if?resd<=err
????f_loop=0;
????disp(‘Find?Solution‘);
????n_it
????x_old
????resd;
????
else
????f_loop=1;
end
his_alp?=?[];
beta=0;
d_pre=zeros(21);
while?f_loop
????d?=?-h_old*gf_old;
????phia?=?@(al)funf(x_old+al*d);
????alp?=?fminbnd(phia010);
????his_alp=[his_alp;alp];
????x_new?=?x_old+alp*d;
????s_old?=?x_new-x_old;
????f_new?=?funf(x_new);
????gf_new?=?gradf(x_new);
????y_old?=?gf_new-gf_old;
????w_old?=?w(h_oldy_olds_old);
????h_old=hessi(h_oldy_olds_oldw_old)
????resd=norm(gf_newinf);
????if?resd<=err
????????disp(‘Solution?Found!‘);
????????n_it=n_it+1
????????x_old=x_new
????????resd=norm(gf_newinf);
????????his_x=[his_x;x_old‘];
????????his_ep=[his_ep;resd];
????????return
????elseif?n_it>1000
????????disp(‘toomach?its!‘);
????????n_it;
????????return?
????else
????????x_old?=?x_new;
????????his_x=[his_x;x_old‘];
????????f_old=f_new;
????????gf_old=gf_new;
????????resd=norm(gf_old);
????????his_ep=[his_ep;resd];
????????n_it?=?n_it+1;
????end
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-12?20:25??2_劉董經(jīng)典_63174_共軛梯度算法\
?????文件????????1235??2018-11-12?20:15??2_劉董經(jīng)典_63174_共軛梯度算法\bfgs.m
?????文件?????????125??2018-11-12?19:25??2_劉董經(jīng)典_63174_共軛梯度算法\div_1.m
?????文件????????1736??2018-11-12?20:15??2_劉董經(jīng)典_63174_共軛梯度算法\FR.m
?????文件??????????60??2018-11-07?20:43??2_劉董經(jīng)典_63174_共軛梯度算法\funf.m
?????文件??????????88??2018-11-07?20:33??2_劉董經(jīng)典_63174_共軛梯度算法\gradf.m
?????文件?????????164??2018-11-12?19:50??2_劉董經(jīng)典_63174_共軛梯度算法\hessi.m
?????文件?????????146??2018-11-12?20:05??2_劉董經(jīng)典_63174_共軛梯度算法\w.m
?????文件???????20923??2018-11-12?19:42??2_劉董經(jīng)典_63174_共軛梯度算法\實(shí)驗(yàn)二.docx
評論
共有 條評論