Closed Form Solution for the Equations of Motion for Constrained Linear Mechanical Systems and Generalisations : An Algebraic Approach