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
%   04/23/2001

if nargin < 2,
    ord = 0;
end

if ord == 0,
    % y = 100(x_2 - x_1^2)^2 + (1-x_1)^2
    y = 100*(x(2,:) - x(1,:).^2).^2 + (1-x(1,:))^2;

elseif ord == 1,
    %        400(x_1^2 - x_2)x_1 - 2(1-x_1)
    % y' =
    %                200(x_2-x_1^2)
    tmp = x(2,:)-x(1,:).^2;
    y = [(2 - 400*tmp).*x(1,:) - 2; ...
         200*tmp];

elseif ord == 2,
    %       1200x_1^2 - 400x_2 + 2         -400x_1
    % y'' =
    %             -400x_1                    200
    % For y'', we do not accept a list of x.
    y = [1200*x(1)^2 - 400*x(2)+2, -400*x(1); ...
         -400*x(1),                200];
else
    error('ord should be 0, 1, or 2');
end
