Start with Newton’s Second Law
Let \(\vec F_{\alpha}\) be total force acting on \(\alpha ^{th}\) particle. The equations of motion are $$\vec F_α = \frac d {dt} \vec p_α, \hspace{.5em} α = 1, ... \hspace{5em}(2)$$
\(\vec p_{\alpha} =\) momentum of \(α^{th}\) particle. $$(or) \hspace{.5em} \left(\vec F_α  \frac d {dt} \vec p_α \right) = 0 \hspace{5em} (3)$$
For small displacements \(\delta \vec r_{\alpha}\), we have
$$\left(\vec F_α  \frac d {dt} \vec p_α \right) . \delta \vec r_α = 0 \hspace{5em} (4)$$
Summing over all particles
$$\sum _{α=1}^N \left(\vec F_α  \frac d {dt} \vec p_α \right).\delta \vec r_α = 0 \hspace{5em} (5)$$
4.1 Net force on a particle is a sum of external forces and forces due to constraint
We write total force \( \vec F_{\alpha}\) as
$$\vec F_α = \vec F_α^{(e)} + \vec f_α \hspace{5em} (6)$$
where \( \vec F_{\alpha}^{(e)}\) is total force on \(\alpha^{th}\) particle excluding the force due to constraint \(\vec f_{\alpha}\).
Eliminating forces of constraints
Since the system is in equilibrium under forces of constraint, therefore virtual work
principle gives
$$\sum \vec f_α . \delta \vec r_α = 0 \hspace{5em} (7)$$
Note that this important fact eliminates the forces of constraints.
Eqs.(5)  (7) give
$$\sum _{α = 1}^N \left( \vec F_α^{(e)}  \frac d {dt} \vec p_α \right) . \delta \vec r_α = 0 \hspace{5em} (8)$$
where \(\delta \vec r_{\alpha}\) is virtual displacement of the system. This result (8) is known de Alembert’s principle.
4.2 Express ’total work done’ in terms of generalised coordinates
The first term in Eq.(8), \(\sum _{\alpha = 1} ^N \left(\vec F_{\alpha}^{(e)} . \delta \vec r_{\alpha} \right)\) is the work done due to external forces.
Next steps below are straightforward differential calculus manipulations. The strategy now is to introduce generalised coordinates \(q_k, k = 1, 2, 3, · · ·\) and

This result is known de Alembert’s principle. to express \(\delta \vec r_{\alpha}\) in terms of \(\delta q_k\)
$$\sum _α \delta \vec r_α \longrightarrow \sum _k \delta q_k$$ 
to leave \( \vec v_{\alpha}\), coming from \( \vec p_{\alpha}\), alone. No attempt is made to change to \( \dot{q}_k, q_k\) because we shall try to get final answer in terms of \(T = \frac 1 2 m_{\alpha} \vec v_{\alpha}^2\).
The Cartesian components of position vectors can be expressed as functions of \(q_k, k = 1, 2, ..N\).
$$\vec r_α = \vec r_α (q_1, q_2, ..., q_N, t) \hspace{5em} (9)$$
The virtual displacements \(\delta \vec r_{\alpha}\) in (7) are given by
$$\delta \vec r_α \sum _j \frac {\partial \vec r_α} {\partial q_j} \delta q_j. \hspace{5em} (10)$$
Remember that the coordinates \(q_k\) in \( \vec r_{\alpha}\), see Eq.(9), change with time during the motion. Hence \(\frac {\partial \vec r_{\alpha}} {\partial q_j}\) in (10), carry implicit time dependence. By adding and subtracting a suitable term, we rewrite the second term in expression (8) as
\(\hspace{4em} \sum _{\alpha} \frac {d \vec p_{\alpha}} {dt} . \delta \vec r_{\alpha} = \sum _{j,\alpha} \Bigg\{ \left[ \frac d {dt} (m_{\alpha} \vec v_{\alpha}) \right] \left[\frac {{\partial} \vec r_{\alpha}} {{\partial} q_j} \right] \Bigg\} \delta q_j \hspace{5em} (11)\)
\(\hspace{9.5em} = \sum _{j,\alpha} \left\{ \frac d {dt} \left[ \left( m_{\alpha} \vec v_{\alpha} \right) \left( \frac {{\partial} \vec r_{\alpha}} {{\partial} q_j} \right) \right]  m_{\alpha} v_{\alpha} \left[ \frac d {dt} \frac {\partial \vec r_{\alpha}} {\partial q_j} \right] \right\} \delta q_j \hspace{2em} (12)\)
4.3 Bring in kinetic energy
Next we will show that the two terms in curly brackets in (11) can be written as derivatives of kinetic energy
$$\frac d {dt} \left[ \left( m_α \vec v_α \right) . \left( \frac {\partial \vec r_α} {\partial q_j} \right) \right] = \frac d {dt} \left( \frac {\partial T} {\partial \dot q_j} \right) \hspace{5em} (13)$$
$$m_α \vec v_α . \left[ \frac d {dt} \frac {\partial \vec r_α} {\partial q_j} \right] = \frac {\partial T} {\partial q_j} \hspace{5em} (14)$$
Proof of (14) is easy:
We take up (14) first. Exchanging the order of differentiations w.r.t. \(t\) and \( \vec r_{\alpha}\) gives
$$m_α \vec v_α \frac d {dt} \left( \frac {\partial \vec r_α} {\partial q_j} \right) = m_α \vec v_α . \frac {\partial} {\partial q_j} \left( \frac {d \vec r_α} {dt} \right) = m_α \vec v_α . \frac {\partial \vec v_α} {\partial q_j}$$
$$= \frac {\partial} {\partial q_j} \left( \frac 1 2 m_α \vec v_α^2 \right) = \frac {\partial T} {\partial q_j} \hspace{5em} (15)$$
Proof of (13) requires a trick:
Differentiating (9) w.r.t. to time t we get
$$\frac {d \vec r_α} {dt} = \sum _j \frac {\partial \vec r_α} {\partial q_j} \dot q_j + \frac {\partial \vec r_α} {\partial t} \bigg q_k , \hspace{5em} (16)$$
$$or \hspace{1em} \vec v_α = \sum _j \frac {\partial \vec r_α} {\partial q_j} \dot q_j + \frac {\partial \vec r_α} {\partial t}. \hspace{5em} (17)$$
Note that the velocities \(\vec v_{\alpha}\) depend on \(q, \dot q\) and t. Differentiating (17) w.r.t \(\dot q_k\) we get
$$\frac {\partial \vec v_α} {\partial \dot q_k} = \frac {\partial \vec r_α} {\partial q_j}. \hspace{5em} (18)$$
We shall use this relation to eliminate \(\frac {\partial \vec r_\alpha} {\partial q_j}\) in (13).
$$\sum_α \frac d {dt} \left[ \left( m_α v_α \right) \left( \frac {\partial \vec r_α} {\partial q_j} \right) \right] = \sum_α \frac d {dt} \left[ \left( m_α v_α \right) \frac {\partial \vec v_α} {\partial \dot q_j} \right] = \frac d {dt} \sum_α \left( m_α \vec v_α \frac {\partial \vec v_α} {\partial \dot q_j} \right)$$
$$= \frac d {dt} \sum _α \frac \partial {\partial \dot q_k} \left( \frac 1 2 m_α \vec v_α^2 \right)$$
$$= \frac d {dt} \left( \frac {\partial T} {\partial \dot q_k} \right) \hspace{5em} (19)$$
where \(T\) is the kinetic energy of the system
$$T = \sum_α \frac 1 2 m_α \vec v_α^2$$
Thus Eq.(12) can be written as
\(\hspace{4em} \sum _{\alpha} \frac {d \vec p_{\alpha}} {dt} . \delta \vec r_{\alpha} = \sum _{j,\alpha} \left\{ \left[ \frac d {dt} \left( m_{\alpha} \vec v_{\alpha} \right) \right] \left[ \frac {{\partial} \vec r_{\alpha}} {{\partial} q_j} \right] \right\} \delta q_j\)
\(\hspace{9.5em} = \sum _{j,\alpha} \left\{ \frac d {dt} \left[ \left( m_{\alpha} \vec v_\alpha \right) \left( \frac {\partial \vec r_\alpha} {\partial q_j} \right) \right]  m_\alpha v_\alpha \left[ \frac d {dt} \frac {\partial \vec r_\alpha} {\partial q_j} \right] \right\} \delta q_j\)
$$= \sum _j \left[ \frac d {dt} \left( \frac {\partial T} {\partial \dot q_j} \right)  \frac {\partial T} {\partial q_j} \right] \delta q_j \hspace{5em} (20)$$
Thus Eq.(14) can be cast in the form
\(\hspace{4em} \sum \left( \frac d {dt} \frac {\partial T} {\partial \dot q_k}  \frac {\partial T} {\partial q_k} \right) \delta q_k = \sum _{k,{\alpha}} \left( F_{\alpha}^{(e)} . \frac {\partial \vec r_{\alpha}} {\partial q_k} \right) \delta q_k \hspace{7em} (21)\)
4.4 Define Generalized force
The expression
$$\sum _α F_α^{(e)} . \frac {\partial \vec r_α} {\partial q_k} \equiv Q_k \hspace{5em} (22)$$
will be called generalized force. In terms of generalized force, Eq.(21) becomes
$$\hspace{4em} \sum _k \left[ \left(\frac d {dt} \frac {\partial T} {\partial \dot q_k}  \frac {\partial T} {\partial q_k} \right)  Q_k \right] \delta q_k = 0 \hspace{7em} (23)$$
4.5 The variations in generalized coordinates are independent
Calculus manipulations being over, it is time to use the fact that the generalized coordinates are independent
Since \(\delta q_k\) are independent and arbitrary the coefficient of each \(\delta q_k\) in the above equation can be set equal to zero.
$$ \left(\frac d {dt} \frac {\partial T} {\partial \dot q_k}  \frac {\partial T} {\partial q_k} \right) = Q_k \hspace{7em} (24)$$
We will now consider two different special cases.