Derive the expression for the magnetic energy stored in a solenoid

Derive the expression for the magnetic energy stored in a solenoid in terms of magnetic field B, area A and length l of the solenoid carrying a steady current I. How does this magnetic energy per unit volume compare with the electrostatic energy density stored in a parallel plate capacitor ?

Rate of work done
$\frac{dW}{dt}=\left| \varepsilon \right|$
$I=\left[ LI\frac { dI }{ dt } \right]$
$dW=LIdI$
Total amount of work done
$\int{dW=\int{LIdI}}$
$W=\frac{1}{2}L{{I}^{2}}$
For the solenoid:
Inductance, $L={{\mu }{0}}{{n}^{2}}Al$ ;
$B={{\mu }
{0}}nI$
$\therefore W={{U}{B}}=\frac{1}{2}L{{I}^{2}}$
$=\frac { 1 }{ 2 } ({ \mu { 0 } }{ n^{ 2 } }Al){ \left[ { \frac { B }{ { { \mu { 0 } }n } } } \right] ^{ 2 } }$
$=\frac{{{B}^{2}}Al}{2{{\mu }
{0}}}$
Magnetic energy per unit volume
$=\frac{{{B}^{2}}}{2{{\mu }
{0}}}$
Also, Electrostatic energy stored per unit volume
$=\frac{1}{2}{{\varepsilon }
{0}}{{E}^{2}}$