clear all syms f(x1,x2) gradf(x1,x2) Hf(x1,x2); f(x1,x2) = -log(1-x1-x2)-log(x1)-log(x2); gradf(x1,x2)=gradient(f); Hf(x1,x2)=hessian(f); N=30;%number of Newton iterations tol=0.00001; x=zeros(2,N); fval=zeros(N,1); er=zeros(N,1); x(:,1)=[.8;.1];%initial point k=1;while norm(double(gradf(x(1,k),x(2,k)))) > tol && k < N fval(k) = double(f(x(1,k),x(2,k))); er(k)=norm([1/3;1/3]-x(:,k)); x(:,k+1) = x(:,k) - double(Hf(x(1,k),x(2,k)))\double(gradf(x(1,k),x(2,k))); k=k+1;end fval(k)=double(f(x(1,k),x(2,k))); er(k)=norm([1/3;1/3]-x(:,k)); format long [(1:k)' x(:,1:k)' er(1:k) fval(1:k)]