It may (some times) be impossible to find a Lagrangian that identically reproduces a given set of equations as its Euler-Lagrange equations. Indeed, action principle is not very useful for describing systems in which viscosity or heat transfer is important. In most such cases no Lagrangian / action is known. However, if an action /Lagrangian does exist, we can indeed reconstructed. Let me show you how;
We know that if an action [itex]S[\phi][/itex] is given, then the equations of motion are
[tex]E(\phi) = \frac{\delta S[\phi]}{\delta \phi(x)}= 0 \ \ \ (1)[/tex]
where [itex]\delta S / \delta \phi[/itex] is the variation derivative of the action with respect to the dynamical variables [itex]\phi(x)[/itex];
[tex]\delta S[\phi] = \int d^{n}x \frac{\delta S}{\delta \phi(x)} \delta \ \phi(x) \ \ \ (2)[/tex]
Suppose now that eq(1) is given and we want to reconstruct [itex]S[\phi][/itex]. In order to do this, we introduce a (homotopy) parameter [itex]\lambda \in [0,1][/itex], and let
[tex]\phi(x) \rightarrow \lambda \phi(x)[/tex]
in eq(1);
[tex]E(\lambda \phi) = \frac{\delta S}{\delta \phi}|_{\phi = \lambda \phi}[/tex]
Next, we use eq(2) to write the derivative of [itex]S[\lambda \phi][/itex] with respect to [itex]\lambda[/itex];
[tex]
\frac{d}{d\lambda}S[\lambda \phi] = \int d^{n}x \frac{\delta S}{\delta \phi}|_{\phi = \lambda \phi}\ \frac{d}{d\lambda}(\lambda \phi ) = \int d^{n}x \ E(\lambda \phi ) \ \phi (x)[/tex]
Integrating this equation from [itex]\lambda = 0[/itex] to [itex]\lambda = 1[/itex] gives (up to an arbitrary additive constant);
[tex]
S[\phi] = \int d^{n}x \int_{0}^{1} d \lambda \ E(\lambda \phi )\ \phi (x) \ \ \ (3)[/tex]
Finally, we may need to integrate by parts and throw away all surface terms before reading off the Lagrangian from eq(3).
For example let us reconstruct the Lagrangian which leads to the following equation of motion;
[tex]\partial_{a}\partial^{a}\phi + \cos (\phi^{2}) = 0[/tex]
From eq(3) we get , after integrating the 1st term by part,
[tex]
S[\phi] = \int d^{n}x \int_{0}^{1} d\lambda \{ - \lambda \partial_{a}\phi \partial^{a}\phi + \phi \cos (\lambda^{2}\phi^{2}) \}[/tex]
From this we find our Lagrangian;
[tex]
\mathcal{L} = - \frac{1}{2}\partial_{a}\phi \partial^{a}\phi + \int_{0}^{1}d\lambda\ \phi \ \cos (\lambda^{2}\phi^{2})[/tex]
Ok, I leave you to reconstruct an action/ Lagrangian which has
[tex]\partial_{a}\partial^{a}\phi - \sin (\phi) = 0[/tex]
as its Euler-Lagrange equation.
Regards
sam