Solution (source code)

= Solution

Write the action density as
$$
\mathcal L
=a^3\left[
\frac12\dot\phi^2
-\frac{c^2}{2a^2}\nabla\phi\cdot\nabla\phi
-V(\phi)
\right].
$$
Under a compactly supported <variation> $\phi\mapsto\phi+\epsilon\eta$,
$$
\delta S
=\int d^3x\,dt
\left[
a^3\dot\phi\,\dot\eta
-ac^2\nabla\phi\cdot\nabla\eta
-a^3V'(\phi)\eta
\right].
$$
Integrating the first term by parts in time and the second in space, and discarding the <boundary condition>[boundary terms], gives
$$
\delta S
=\int d^3x\,dt
\left[
-\frac{\partial}{\partial t}(a^3\dot\phi)
+ac^2\nabla^2\phi
-a^3V'(\phi)
\right]\eta.
$$
The <principle of stationary action> requires this to vanish for every $\eta$. Since
$$
\frac{\partial}{\partial t}(a^3\dot\phi)
=a^3(\ddot\phi+3H\dot\phi),
$$
division by $-a^3$ yields the field <Euler-Lagrange equation>
$$
\boxed{
\ddot\phi+3H\dot\phi
-\frac{c^2}{a^2}\nabla^2\phi
+\frac{dV}{d\phi}=0
}.
$$
This is the equation generated by the <inflaton action in an expanding universe>.