Obtaining Euler-Lagrange equations for a mass attached to a spring, connected to a pendulum via a pulley [closed]

I'm trying to setup the Lagrangian for the following system, I'm quite confident this is correct, but I would like a second pair of eyes to analyse my solution. Here is the problem at hand

A block with mass $$M$$ lies on a slippery horizontal table. The block is connected to a solid wall via a spring with spring constant $$k$$. From the block a thin, weightless and inelastic string is drawn over a weightless and frictionless pulley T. In its other end the string holds a particle with mass $$m$$, that can swing in a vertical plane. Set up Lagrange’s equations for oscillations around the equilibrium configuration, and solve them for the case of small oscillations.

Here is a sketch of the situation:

Note in the sketch that $$\theta$$ is omitted. Defining directions as in the sketch, and our first generalised coordinate $$x$$ as the distance from the equilibrium of the block, and our second generalized coordinate $$y$$ as the length of the pendulum, and finally $$\theta$$ as the angle of the pendulum with respect to the vertical, it ought to be the case that if the pendulum has equilibrium length $$\ell$$, $$y=x+\ell$$, which is a constraint for our system.

The position of the block is simply $$\overline{r}_1=x\hat{i}$$, and that of the pendulum is $$\overline{r}_2=(-y\sin{\theta})\hat{i}+(y\cos{\theta})\hat{j}$$. We could have ofcourse considered the picture differently to obtain $$(y\sin{\theta})\hat{i}$$. Now, \begin{align} \dot{\overline{r}}_2&=(-(\dot{y}\sin{\theta}+y\cos{\theta}\dot{\theta}))\hat{i}+(\dot{y}\cos{\theta}-y\sin{\theta}\dot{\theta})\hat{j} \end{align} $$\dot{\overline{r}}_2^2=\dot{y}^2+y^2\dot{\theta}^2$$ Now, the potential energy of the system is simply given by (ignoring constant terms from gravitational potential) $$U=\frac{1}{2}kx^2-mgy\cos{\theta}$$ Substituting $$y=x+l$$, one obtains $$\mathcal{L}=\frac{1}{2}M\dot{x}^2+\frac{1}{2}m\left(\dot{x}^2+(x+\ell)^2\dot{\theta}^2\right)-\frac{1}{2}kx^2+mg(x+\ell)\cos{\theta}$$ which is how I would set up the Lagrangian. We then obtain Euler-Lagrange equations $$m(x+\ell)\dot{\theta}^2-kx+mg\cos\theta=\ddot{x}(M+m)$$ by taking derivatives with respect to $$x$$ and $$\dot{x}$$. For the $$\theta$$ equation, we obtain $$-mg(x+\ell)\sin{\theta}=m(x+\ell)^2\ddot{\theta}.$$ Does this seem correct?

Let's go through each step you've taken to evaluate the correctness of your approach.

Position and Velocity Vectors

1. You define the position of the block as $${r}_1 = x\hat{i}$$. This is correct.
2. You define the position of the pendulum as $${r}_2 = (-y \sin \theta) \hat{i} + (y \cos \theta) \hat{j}$$. This is also correct.
3. Your expression for$${r}_2$$ in terms of $$\dot{y}$$ and $$\dot{\theta}$$ looks appropriate.
4. Your expression for $$\dot{\vec{r}}_2^2$$ is also correct.

Potential Energy ( U )

You define the potential energy ( U ) as $$U = \frac{1}{2} k x^2 - mgy \cos \theta$$ This looks good, but it's worth noting that the gravitational potential energy is often written as ( -mgy ) where ( y ) is the height from a reference point, not ( -mgy \cos \theta ). However, if you're considering variations from the vertical position, then ( -mgy \cos \theta ) would be appropriate.

The Lagrangian ( L )

You express ( L ) as

$$L = \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m (\dot{x}^2 + (x + \ell)^2 \dot{\theta}^2) - \frac{1}{2} k x^2 + mg(x + \ell) \cos \theta$$ It's generally okay, but I'd like to point out that:

1. The kinetic energy term for the block $$\frac{1}{2} M \dot{x}^2$$ is correct.
2. The kinetic energy term for the pendulum mass ( m \ seems to be correct too, as $$\frac{1}{2} m (\dot{x}^2 + (x + \ell)^2 \dot{\theta}^2)$$ includes both the translational and rotational kinetic energies.
3. The potential energy term seems okay, especially if $$\cos \theta$$ is what you want to use to describe variations from vertical.

Euler-Lagrange Equations

You obtained:

1. $$( m(x+\ell) \dot{\theta}^2 - kx + mg \cos \theta = \ddot{x}(M+m)$$
2. $$( -mg(x+\ell) \sin \theta = m(x+\ell)^2 \ddot{\theta}$$

These equations appear to be correct for your defined ( L ), but it would be helpful to go through the Euler-Lagrange equations' derivation step-by-step for better clarity.

To double-check your equations of motion, we'll start by using the Lagrangian you've provided:

$$L = \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m (\dot{x}^2 + (x + \ell)^2 \dot{\theta}^2) - \frac{1}{2} k x^2 + mg(x + \ell) \cos \theta$$

To derive the equations of motion, we'll apply the Euler-Lagrange equation:

$$\frac{d}{dt} \left( \frac{\partial L}{\partial \dot{q}_i} \right) - \frac{\partial L}{\partial q_i} = 0$$

where $$( q_i)$$ are the generalized coordinates. Here ( q_1 = x ) and $$q_2 = \theta$$

Equation for ( x )

1. $$\frac{\partial L}{\partial \dot{x}} = M \dot{x} + m \dot{x} = (M + m) \dot{x}$$
2. $$\frac{d}{dt} \left( (M + m) \dot{x} \right) = (M + m) \ddot{x}$$
3. $$\frac{\partial L}{\partial x} = m \ell \dot{\theta}^2 - kx + mg \cos \theta$$

Thus, the Euler-Lagrange equation for ( x ) becomes:

$$(M + m) \ddot{x} = m \ell \dot{\theta}^2 - kx + mg \cos \theta$$

Equation for ( \theta )

1. $$\frac{\partial L}{\partial \dot{\theta}} = m (x + \ell)^2 \dot{\theta}$$
2. $$\frac{d}{dt} \left( m (x + \ell)^2 \dot{\theta} \right) = 2m (x + \ell) \dot{x} \dot{\theta} + m (x + \ell)^2 \ddot{\theta}$$
3. $$\frac{\partial L}{\partial \theta} = -mg (x + \ell) \sin \theta$$

Thus, the Euler-Lagrange equation for ( \theta ) becomes:

$$2m (x + \ell) \dot{x} \dot{\theta} + m (x + \ell)^2 \ddot{\theta} = -mg (x + \ell) \sin \theta$$

After simplifying, we get:

$$m (x + \ell)^2 \ddot{\theta} = -mg (x + \ell) \sin \theta$$ It appears that the Euler-Lagrange equations derived from your Lagrangian are indeed correct. Your equations for $$( x )$$ and $$\theta$$ match the ones derived here, confirming your initial setup.