Suppose there is a object M, (sliding motion) moving by the initial speed $v$ and the initial location $x_0$. Otherwise noted, friction is assumed to be nonexistent. It then meets a circular mold with the radius $R$ that the object travels (perimeter). After traveling one round of the mold, it moves onto the right straight path then meets with the path with friction, given by friction coefficient $\mu_k$. When colliding with the wall at $x=d$, the collision is perfectly elastic collision. The object moves back to the original initial position, $x_0$, then bounces with some object, with perfect elastic collision, back to continue the cycle.
The question is, I do know how to describe the movement of the object in Newtonian way, but I would like to know how I would be able to describe the movement using Lagrangian mechanics (or Hamiltonian mechanics).