Dynamic Response of Mechanical Systems by a Weak Hamiltonian Formulation