function y = objective (x, ord)
%OBJECTIVE  Values about the objective function
%
%   y = objective(x, ord) = d^ord y / d x^ord at point x.

%   Ling Li, Caltech
%   06/06/2001

global l a

if nargin < 2,
    ord = 0;
end

c1 = x' * x - 10;
c2 = x(2)*x(3) - 5*x(4)*x(5);
c3 = x(1)^3 + x(2)^3 + 1;
c = [c1; c2; c3];
f = exp(prod(x));

if ord == -1,       % used in aug_lagran
    y = c;

elseif ord == 0,
    y = f + (a/2*c - l)' * c;

elseif ord == 1,    % y'
    dc1 = 2*x;
    dc2 = [0; x(3); x(2); -5*x(5); -5*x(4)];
    dc3 = [3*x(1)*x(1); 3*x(2)*x(2); 0; 0; 0];
    dc = [dc1, dc2, dc3];
    df = [x(2)*x(3)*x(4)*x(5); ...
          x(1)*x(3)*x(4)*x(5); ...
          x(1)*x(2)*x(4)*x(5); ...
          x(1)*x(2)*x(3)*x(5); ...
          x(1)*x(2)*x(3)*x(4)];

    y = df * f + dc * (a*c - l);

else
    error('ord should be -1, 0 or 1');
end
