Numerical solution of dynamical systems by direct application of Hamilton's principle