Virtual displacement for a block sliding down a wedge 
A block slides on a frictionless wedge which rests on a smooth horizontal plane. There are two constraints in this system. One that the wedge can only move horizontally and another that the block must remain in contact with the wedge.
We want to find the virtual displacements for the two block system.
To find those virtual displacements we imagine to freeze the constraints and look for the possible displacements.
Now if I freeze the constraints then the wedge cannot move. The only possible motion is that the small block slides parallal along the incline. However I have found on many articles online that there is a virtual displacement for the wedge as well.
This confuses me how to view the virtual displacements in this case. Can anyone please explain this.
 A: If the block is accelerated down the ramp, it gains momentum, but momentum is conserved, so the ramp must move in the other direction.
This can be calculated using Lagrangian mechanics as follows:

*

*The kinetic energies of the block ($b$) and the wedge ($w$) are
$$
T_b = \frac 12 m_b (({\underbrace{\dot d \cos(\alpha) - \dot x}_{\text{net velocity of the block in $x$-direction}}})^2 + \dot d^2 \sin^2(\alpha))~, \qquad T_w = \frac 12 m_w \dot x^2~,
$$
where $m$ denotes the mass, $d$ is as in your sketch and $x$ is the coordinate parallel to the horizontal plane.


*The potential energies are
$$
V_b = m_b g (h - d\sin(\alpha))~, \qquad V_w = 0~,
$$
where $h$ denotes the maximum height of the wedge.


*The Lagrangian is
$$
\mathcal L = T_b + T_w - V_b - V_w = \frac 12 m_b (\dot d \cos(\alpha) - \dot x)^2 + \frac 12 m_b \dot d^2 \sin^2(\alpha) + \frac 12 m_w \dot x^2 - m_b g (h - d\sin(\alpha))~,
$$
and $d,x$ are the independent variables. Because of
$$
(\dot d \cos(\alpha) - \dot x)^2 = \dot d^2 \cos^2(\alpha) - 2 \dot d \dot x\cos(\alpha) + \dot x^2~,
$$
and $\sin^2(\alpha) + \cos^2(\alpha) = 1$, it holds
$$
\mathcal L = \frac 12 m_b \dot d^2 - \frac 12 m_b \dot d \dot x \cos(\alpha) + \frac 12 (m_b + m_w) \dot x^2 - m_bg(h - d \sin(\alpha))~.
$$


*The Euler-Lagrange equations are
$$
\partial_t \partial_{\dot d} \mathcal L = \partial_d \mathcal L \qquad \Leftrightarrow \qquad m_b \ddot d - \frac 12 m_b \ddot x \cos(\alpha) = m_b g \sin(\alpha)~, \tag{1}
$$
$$
\partial_t \partial_{\dot x} \mathcal L = \partial_x \mathcal L \qquad \Leftrightarrow \qquad \frac 12 m_b \ddot d \cos(\alpha) + (m_b + m_w) \ddot x = 0~. \tag{2}
$$


*From equation (2) there follows
$$
\ddot x = - \frac 12 \frac{m_b}{m_b + m_w} \ddot d \cos(\alpha)~, \tag{3}
$$
which can be plugged into (1) to obtain
$$
m_b \ddot d + \frac 14 \frac{m_b^2}{m_b + m_w} \ddot d \cos^2(\alpha) = m_b g \sin(\alpha)~.
$$
This can be solved for $\ddot d$:
$$
\ddot d = \frac{ g \sin (\alpha) }{1 + \frac 14 \frac{m_b}{m_b + m_w} \cos^2(\alpha)}~.
$$
And with (3) we find
$$
\ddot x = - \frac{ g \sin (\alpha) }{2 \frac{m_b + m_w}{m_b \cos(\alpha)} + \frac 12 \cos(\alpha)}~.
$$
This result means, that the wedge is accelerated in negative $x$-direction, just like momentum conservation demands.
