% Solve task 3 and 4 by Newton method

iex=2;                      % Cose Task. iex=2 (Task 3 problem) iex=1 (Task 4 problem)

x=[2;3];                    % Initial value

for i=1:5
    g=grad_ex5(x,iex);      % Compute the gradient, g=dJ/dx
    H=hess_ex5(x,iex);      % Compute the Hessian, H=d^J/(dx^T dx)
    
    p=-inv(H)*g;            % Search direction, Newtons method
    x=x+p                   % Iterate for the solution by Newtons method
end