Modeling of hybrid systems by piecewise decomposition