function d = Aufgabe2(A, k)
%Aufgabe2 - compute determinant of a matrix by recursion over its minors.
%
%usage
%  d = Aufgabe2(A, k)
%
%input
%  A : (n,n)-matrix.
%  k : Row index in A.
%
%output
%  d : Determinant of A.
%
%description
%  Aufgabe2 computes the determinant of A by summing over the determinants of its
%  minors in row k. The determinants of the minors are computed by recursion where 
%  the trivial case is a (1,1)-matrix.
%
%author
%  buenau@cs.tu-berlin.de

[n,m] = size(A);
if n ~= m, error('Matrix ist nicht quadratisch'); end

if n == 1  
    % Trivial case.
    d = A(1,1);
else
    d = 0;
    % Sum over minors in row k. 
    for j = 1:n
      d = d + ((-1).^(k+j) )*A(k,j) * Aufgabe2(A([1:(k-1) (k+1):n], [1:(j-1) (j+1):n]), k-1);
    end
end
