正定二次函数的共轭梯度法matlab实现
1、算法过程
2、matlab实现
function [X,min_f]=minGRAD(fx,var,x0)
%%%输入目标函数(正定二次函数)fx,变量var,初始点x0;
%%%采用共轭梯度法计算目标函数的极小值;
%%%输出极小值点X,极小值min_f.
j=jacobian(fx,var);
G=double(jacobian(j,var));
g0=(double(subs(j,var,x0)))';
d=-g0;
x0=x0';
k=0;
eps=10^(-5);
judge=1;
while judge==1
if norm(g0,2)<eps
break
end
lamda=g0'*g0/((d'*G)*d);
x1=x0+lamda*d;
g1=(double(subs(j,var,x1')))';
beta=g1'*g1/(g0'*g0);
d=-g1+beta*d;
x0=x1;
g0=g1;
k=k+1;
end
X=double(x0);
min_f=double(subs(fx,var,x0'));