When the bob hits the ends of the tube it bounces back; the ends are assumed to be perfectly elastic. The two equations of motions for the bob and the pendulum bar are derived using the Lagrangian method which is solved numerically by Mathematica's built-in function NDSolve. The spring is anchored to the left edge of the tube and assumed to be massless and can only move in one direction along the length of the tube. Setting the spring stiffness to zero effectively removes the spring leaving the bob to oscillate freely.