Formulation of equations of motion for a chain of flexible links using Hamilton's principle