function d = determinant(M)
dim = length(M);
if dim == 1
    d = M;
else
    d = 0;
    for i = 1:dim
        minor = minorMatrix(M,1,i);
        d = d + (-1)^(i+1)*M(1,i)*determinant(minor);
    end
end
end

