# Is there a Hamiltonian for the (classical) electromagnetic field? If so, how can it be derived from the Lagrangian?

The classical Lagrangian for the electromagnetic field is

$$\mathcal{L} = -\frac{1}{4\mu_0} F^{\mu \nu} F_{\mu \nu} - J^\mu A_\mu.$$

Is there also a Hamiltonian? If so, how to derive it? I know how to write down the Hamiltonian from the Lagrangian where derivatives are taken only with respect to time, but I can't see the obvious way to generalize this.

-
More on singular Legendre transformations: physics.stackexchange.com/q/30192/2451 , physics.stackexchange.com/q/47847/2451 and links therein. –  Qmechanic Dec 15 '13 at 10:25

Let a theory of $n\geq 1$ fields $\phi^i$ with a Lagrangian density $\mathcal L = \mathcal L(\phi^i, \partial_\mu\phi^i)$ be given. Here we use that standard abuse of notation in which $\phi^i$ denotes the vector whose components are the fields; $\phi^i = (\phi^1, \dots, \phi^n)$.
To obtain the corresponding hamiltonian density, one first defines the following canonical momentum corresponding to the field $\phi^i$: \begin{align} \pi_i(x) = \frac{\partial \mathcal L}{\partial\dot \phi^i}(\phi^i(x), \partial_\mu\phi^i(x)), \qquad \dot\phi^i := \partial_t\phi^i \tag{1} \end{align} Then, the Hamiltian density is \begin{align} \mathcal H = \pi_i\dot\phi^i - \mathcal L \end{align} where a sum over $i$ is implied. Note that as in classical mechanics, on the right hand side of this expression, $\dot \phi^i$ should be replaced with its expression in terms of $\pi_i,\phi^i$ so that the Hamiltonian is a function of $(\pi_i, \phi^i)$ only, namely \begin{align} \mathcal H(\pi_i, \phi^i) = \pi_j \,\dot\phi^j(\pi_i,\phi^i) - \mathcal L(\phi^i, \dot\phi(\pi_i,\phi^i)). \end{align} Again we have abused notation slightly here in writing $\dot\phi^i$ as a function of $\pi_i$ and $\phi^i$. What we mean is the expression for $\dot\phi^i$ is obtained by solving the definition $(1)$ of the canonical momentum for $\dot\phi^i$ in terms of $\pi_i$ and $\phi^i$.
In your case, the fields are $A^\mu$ with corresponding momenta $\pi_\mu$.
It's worth mentioning that you need to add Lagrange multipliers to handle the constraints, e.g., $\Pi_0 = \frac{\delta L}{\delta \dot A_0} = 0$ and so on. Here's a random link –  lionelbrits Dec 14 '13 at 19:38