Calculates the magnitude of a vector.