# Reasoning behind $\delta \dot q = \frac{d}{dt} \delta q$ in deriving E-L equations [duplicate]

Consider a Lagrangian $$L(q, \dot{q}, t)$$ for a single particle. The variation of the Lagrangian is given by:

$$\delta L= \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\delta \dot q\tag1$$

When using Hamilton's Principle ($$\delta S = 0$$):

$$\delta S = \delta \left[ \int L(q, \dot q, t) dt \right] =\int \delta [L(q, \dot q, t)] dt = 0\tag2$$

and the right-hand side of equation (1),

$$\int \left( \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\delta \dot q \right)dt = 0\tag3$$

We then swap the order of time derivative and variation on the second term in the integrand to get:

$$\int \left( \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\frac{d}{dt}(\delta q) \right)dt = 0\tag4$$

Where we then integrate by parts and get the E-L equations.

My question is how do we justify trading the order of time differentiation and the variation on q? What is the argument for the identity $$\delta \dot q = \frac{d}{dt}(\delta q)$$, i.e. to rewrite equation (3) as equation (4).

Well, $$\dot{q}$$ is defined as $$\dot{q}=\frac{dq}{dt}.$$ Hence when $$q\to q+\delta q,$$ we have $$\dot{q}\to \frac{d}{dt}(q+\delta q)=\dot{q}+\frac{d\delta q}{dt}.$$ Identifying this last expression with $$\dot{q}\to\dot{q}+\delta\dot{q},$$ we see that $$\delta\dot{q}=\frac{d\delta q}{dt}.$$