0001 function H = bfgsi(H0,dg,dx)
0002
0003
0004
0005
0006
0007
0008 if size(dg,2)>1
0009 dg=dg';
0010 end
0011 if size(dx,2)>1
0012 dx=dx';
0013 end
0014 Hdg = H0*dg;
0015 dgdx = dg'*dx;
0016 if (abs(dgdx) >1e-12)
0017 H = H0 + (1+(dg'*Hdg)/dgdx)*(dx*dx')/dgdx - (dx*Hdg'+Hdg*dx')/dgdx;
0018 else
0019 disp('bfgs update failed.')
0020 disp(['|dg| = ' num2str(sqrt(dg'*dg)) '|dx| = ' num2str(sqrt(dx'*dx))]);
0021 disp(['dg''*dx = ' num2str(dgdx)])
0022 disp(['|H*dg| = ' num2str(Hdg'*Hdg)])
0023 H=H0;
0024 end
0025 save H.dat H