Problems on calculus of variations I'm reading a paper in which it gives the following Lagrangian
$$L[u,\rho,\phi]=L_0[u,\rho]+\phi(x)(\partial_t\rho+\nabla\cdot(\rho u))$$
where $L_0$ is part of Lagrangian and $\phi(x)$ is Lagrange multiplier, $\rho=\rho(x)$ can be understood as density, $u=u(x)\in\mathbb R^3$ is velocity field. I find my answer different with author's about $\partial L/\partial \rho$. I compute it as the following,
$$\frac{\partial L}{\partial \rho}=\frac{\partial L_0}{\partial \rho}+\phi\left(\frac{\partial}{\partial\rho}(\partial_t\rho+\nabla\rho\cdot u)+\nabla\cdot u\right)$$
and then I can't continue, but author's result is
$$\frac{\partial L_0}{\partial \rho}-\partial_t\phi-u\cdot\nabla \phi$$
Could anybody help?
 A: Remember the variation is to be taken under an integral sign (its the variation of the action functional you are after). This allows us to use integration by parts to rewrite terms. We start by taking the variation of the action $S = \int d^4x L$ (we only consider the variation of $\rho$ below):
$$\delta S = \int d^4x~\left[\delta L_0 + \phi\delta(\dot{\rho} + \nabla\cdot (\rho u))\right] = \int d^4x~\left[\frac{\partial L_0}{\partial \rho}\delta\rho + \phi\left(\frac{\partial}{\partial t}\delta\rho + \nabla\cdot (\delta\rho u)\right)\right]$$
Now we have that $\phi\frac{\partial}{\partial t}(\delta\rho) = \frac{\partial }{\partial t}(\phi \delta\rho) - \delta\rho\frac{\partial}{\partial t}\phi$ and $\phi\nabla \cdot (\delta\rho u) = \nabla\cdot(\phi\delta\rho u) - \nabla\phi\cdot u\delta\rho$. Substitute this into the integral and we get
$$\delta S  = \int d^4x~\left[\frac{\partial}{\partial t}(\phi \delta\rho) +  \nabla\cdot(\phi\delta\rho u) + \delta\rho\left(\frac{\partial L_0}{\partial \rho} - \frac{\partial\phi}{\partial t} - \nabla\phi\cdot u\right)\right]$$
The first two terms can be integrated to yield surface-terms - the first directly, the second one using the divergence theorem.  The surface terms we assume vanish and usually this follows from the boundary conditions one impose. This leaves us with
$$\delta S = \int d^4x~\left[ \frac{\partial L_0}{\partial \rho} - \frac{\partial\phi}{\partial t} - \nabla\phi\cdot u\right]\delta\rho$$
${\bf Added:}$
Another, and more direct, way to do this is to use the Euler-Lagrange equations which says that
$$0 = \frac{dL}{d\rho}  - \nabla_{\mu}\left(\frac{dL}{d\rho_{,\mu}}\right) = \frac{dL}{d\rho}  - \frac{d}{dt}\frac{dL}{d\dot{\rho}} - \nabla_i \frac{dL}{d\nabla_i\rho}$$
where $\rho_{,\mu}$ is the derivative with respect to the $\mu$'th coordinate and a repeated index means you should sum over it. By writing out 
$$L = L_0 + \phi(\dot{\rho} + \nabla\rho\cdot u + \rho \nabla\cdot u) $$
we find
$$\frac{dL}{d\rho} = \frac{dL_0}{d\rho} + \phi\nabla\cdot u,~~~~~~\frac{dL}{d\dot{\rho}} = \phi,~~~~~\frac{dL}{d\nabla_i\rho} = \phi u_i$$
which gives
$$\frac{dL_0}{d\rho} + \phi\nabla\cdot u - \dot{\phi} - \nabla_i ( \phi u_i) = 0$$
which is the same equation since $ \nabla_i ( \phi u_i) = \phi\nabla\cdot u + \nabla\phi\cdot u$.
