Starting from the expression for the energy

Starting from the expression for the energy W = $\frac { 1 }{ 2 } L{ I }^{ 2 }$, stored in a solenoid of self-inductance L to build up the current I, obtain the expression for the magnetic energy in terms of the magnetic field B, area A and length l of the solenoid having n number of turns per unit length. Hence show that the energy density is given by $\frac { { B }^{ 2 } }{ 2{ \mu }_{ 0 } } $

Given:
Energy W = $\frac { 1 }{ 2 } L{ I }^{ 2 }$
A solenoid having magnetic field B, area A, & length l and having n numbers of turns per unit length.Self-inductance of the solenoid is given by:
$L={ \mu }{ 0 }{ n }^{ 2 }lA$
$B={ \mu }
{ 0 }nI$
$\therefore \quad W=\frac { 1 }{ 2 } { \mu }{ 0 }{ n }^{ 2 }lA{ I }^{ 2 }$
$\therefore \quad { B }^{ 2 }={ \mu }
{ 0 }{ n }^{ 2 }{ I }^{ 2 }$
V = AL (volume)
=>$[W = \frac{1}{{2{\mu _0}}}\mu _0^2{n^2}{I^2}]$
=>$[W = \frac{1}{{2{\mu _0}}}{B^2}V]$
$[Energy;density = \frac{W}{V} = \frac{{{B^2}}}{{2{\mu _0}}}]$