$\therefore \quad W=U=\frac{1}{2} \times$ Stress $\times$ Strain $\times$ Volume
OR $\quad W=\frac{1}{2} \times Y(\text { Strain })^{2} \times$ Volume $……(1)$
$(\text {Strain}=Y \times$Strain)
Strain $=\frac{x}{L}$and volume $=A L$
$\therefore W=\frac{1}{2} \times Y \times \frac{x^{2}}{L^{2}} \times A L \quad \Longrightarrow W=\frac{Y x^{2} A}{2 L}$