新浪博客

拟牛顿法的matlab实现

2014-10-21 17:34阅读:
牛顿法成功的关键是利用了Hesse矩阵提供的曲率信息,但计算Hesse矩阵工作量大,并且有的目标函数的Hesse矩阵很难计算,甚至不好求出。针对这一问题,拟牛顿法比牛顿法更为有效。这类算法仅利用目标函数值和一阶导数的信息,构造出目标函数的曲率近似,使方法具有类似牛顿法的收敛速度快的优点。
函数名:quasi_Newton(f,x0,error),
参数:f:待求梯度函数 x0:初始点 error:允许误差
主程序:
function A=quasi_Newton(f,x0,error)
[a,b]=size(x0);
G0=eye(b);
initial_gradient=gradient_my(f,x0,b);
norm0=0;
norm0=initial_gradient*initial_gradient';
syms step_zzh;
A=[x0];
search_direction=-initial_gradient;
x=x0+step_zzh*search_direction;
f_step=subs(f,findsym(f),x);
best_step=golden_search(f_step,-15,15);
x_1=x0+best_step*search_direction;
A=[A;x_1];
k=1;
while norm0>error
ox=x_1-x0;
og=gradient_my(f,x_1,b)-initial_gradient;
G1=G0+(ox'*ox)/(ox*og')-(G0*og'*og*G0)/(og*G0*og');
if k+1==b
new_direction=-gradient_my(f,x_1,b);
else
new_direction=-(G1*(gradient_my(f,x_1,b))')';
end
x=x_1+step_zzh*new_direction;
f_step=subs(f,findsym(f),x);
best_step=golden_search(f_step,-15,15)
x_2=x_1+best_step*new_direction
A=[A;x_2];
initial_gradient=gradient_my(f,x_1,b);
norm0=initial_gradient*initial_gradient';
x0=x_1;x_1=x_2;
G0=G1;
k=k+1;
end

我的更多文章

下载客户端阅读体验更佳

APP专享