function [f,g,Hessian]=fun(x)

% ACM40990 / Line-Search Methods #1
%
% Matlab function to generate the cost function, gradient, 
% and Hessian of the Rosenbrock function:
%
% f(x1,x2)=aa(x2-x1^2)^2+(1-x1)^2
%
% Notation:
%
% aa is the prefactor in front in the Rosenbrock function, aa=100 in the
% exercises.
%
% Also,
%
% x1\equiv x
% x2\equiv y

aa=100;

x1=x(1);
x2=x(2);

f=aa*(x2-x1*x1)^2+(1-x1)^2;

g1=2*aa*(x2-x1*x1)*(-2*x1)-2*(1-x1);
g2=aa*(x2-x1*x1)*2;

g=[g1;g2];

B11=2*aa*(x2-x1*x1)*(-2)+2+2*aa*(-2*x1)*(-2*x1);
B12=2*aa*(-2*x1);
B22=2*aa;

Hessian=[B11,B12;B12,B22];


end