function [f,g,H] = rosen(x,Hessflag) % ROSENBROCK % % INPUTS: % X - a 2-D vestor % PARAMS - Not used, but included for compatibility with LINESEARCH % % OUTPUT: % F - a scalar, the Rosenbrock evaluated at X % G - a 2x1 vector, the Gradient of the Rosenbrock evaluated at X % % This function evaluates the Rosenbrock function: % f: R^2 ---> R % x=[x1; x2] |---> 100(x2-x1^2)^2 + (1-x1)^2 % % as well as its gradient: % g: R^2 ---> R^2 % g=[x1; x2] |---> [-400*x1*(x2-x1^2) - 2(1-x1); 200(x2-x1^2)] % % And finally, also the hessian of f. % % H = [-400*(x2-3*x1^2) + 2, 400*x1; % -400*x1, 200] f=100*(x(2)-x(1).^2).^2 + (1-x(1)).^2; g=[-400*x(1).*(x(2)-x(1).^2)-2*(1-x(1)); 200*(x(2)-x(1).^2)]; H=[-400*(x(2)-3*x(1)^2)+2, -400*x(1); -400*x(1), 200];