Necessary and sufficient conditions for stability of a class of second order switched systems