function varargout = constraints2(x)
% 
% Eingabe:
%   x...n-dimensionaler Vektor
%
% Ausgabe:
%   varargout:
%   1. Argument: Funktionswerte von c (2 x 1 Vektor)
%   2. Argument: Gradient von c (n x 2 Vektor)
%   3. Argument: Hesse'matrix' von c (n x n x 2 Array)
%


c = zeros(2,1);
c(1) = sum(x.^2-1.1);
c(2) = prod(x) - 1;

varargout{1} = c;

if nargout > 1
    n = length(x);
    c_der1 = 2*x;
    c_der2 = zeros(n,1);
    for i = 1:n
        c_der2(i) = prod(x(1:n~=i));
    end
    
    varargout{2} = [c_der1,c_der2];
end

if nargout > 2
    c_Hes = zeros(n,n,2);
    c_Hes(:,:,1) = 2*eye(n);
    for i = 1:n
        for j=i+1:n
            c_Hes(i,j,2) = prod(x(1:n~=i & 1:n~=j));
            c_Hes(j,i,2) = c_Hes(i,j,2);
        end
    end
    varargout{3} = c_Hes;
end

end