Computing the Polar Decomposition and the Matrix Sign Decomposition in Matrix Groups