clear all
toler=1e-9;
fn = @(x) x(1)^4+x(1)*x(2)+(1+x(2))^2;
gfn = @(x) [4*x(1)^3+x(2);x(1)+2*(1+x(2))];
Hfn = @(x) [12*x(1)^2 1; 1  2];
xc=[.75; -1.25];
disp(['starting point is   ',num2str(xc')]);
disp(['starting function value is  ',num2str(fn(xc))]);
disp(['starting norm of gradient  ',num2str(norm(gfn(xc)))]);
iter=1;
while norm(gfn(xc))/(fn(xc)+1) > toler,
	xp=xc - (Hfn(xc))\(gfn(xc));
	disp(' ');
	disp(['at Iteration   ',num2str(iter)]);
        disp(['new point is   ',num2str(xp')]);
	disp(['new function value is  ',num2str(fn(xp))]);
	disp(['new norm of gradient  ',num2str(norm(gfn(xp)))]);
	xc=xp;
	iter=iter+1;
end
