For a uniformly charged parallel plate capacitor (dimensions l × w × d), its potential energy is given by:
$$ U = \frac{Q^2}{2C}\ $$
Now if we insert a material (dimension x × w × d) of dielectric constant K in absence of a battery, then its potential energy is:
$$C_{eq} = \frac{(L-x)\ w\ \varepsilon_0}{d}\ + \frac{K\ x \ w \ \varepsilon_0}{d}\ $$
$$C_{eq} = \frac{(L-x+xK) \ w\ \varepsilon_0}{d}\ $$
(where Ceq is equivalent capacitance of system)
$$ U = \frac{Q^2}{2C_{eq}}\ $$
$$ U = \frac{d\ Q^2}{2(L-x+xK)\ w\ \varepsilon_0}\ .......... (i)$$
But if I derive an expression for potential energy using energy density, it comes out different:
$$ U = \frac{1}{2}\varepsilon_0E^2V\ $$
(let's assume potential energy stored in part of capacitor filled with air (or vacuum) = U1 and with dielectric = U2)
$$ U = U_1 + U_2 $$ $$ U = \frac{1}{2}\varepsilon_0\Big(\frac{σ}{\varepsilon_0}\Big)^2(L-x)\ w\ d\ + \frac{1}{2}K\ \varepsilon_0\Big(\frac{σ}{K\varepsilon_0}\Big)^2\ x\ w\ d\ $$
$$ U = \frac{1}{2}\varepsilon_0\Big(\frac{σ}{\epsilon_0}\Big)^2\Big(L-x+\frac{x}{K}\Big)\ w\ d\ $$ where σ is surface charged density of plates; \$σ = Q/(L \cdot w)\$
$$ U = \frac{1}{2\varepsilon_0}\Big(\frac{Q}{L\cdot w}\Big)^2\Big(L-x+\frac{x}{K}\Big)\ w\ d\ .......... (ii)$$
Why are both expressions different?