% function [f,g,H] = quad(x,pars)
%
%  quadratic function f(x) = (1/2) x^T A x
%
% Inputs
% x    vector of variables
% pars structure containing parameters
%
% Outputs
% f    f(x)
% grad gradient (optional)  \nabla f (x)
% H    Hessian  (optional)  \nabla^2 f(x)
function [f,g,H] = quad(x,pars)
A = [1,2;2,1];
f = (1/2)*x'*A*x;
if (nargout>=2)
  % gradient computation
  g = A*x;
  if (nargout>=3)
   % Hessian computation
   H = A;
  end;
end;
