My query is that suppose an ideal spring is present and is compressed from both the sides by a distance $x_{1}$ from the left and a distance $x_{2}$ from the right. So what will be the potential energy stored in the spring at this moment?
Using the formula $\frac{1}{2} kx^{2}$, should it be $\frac{1}{2} k (x_{1}+x_{2})^2$ or the sum of individual energies $\frac{1}{2} k(x_{1})^2 + \frac12 k(x_{2})^2$? According what I have read it should be the individual sum.
But I can't understand why as if we stretch a spring, say to $y_{1}$ and $y_{2}$ from both side, the force applied by spring on both sides will be $-k(y_{1}+y_{2})$, as the spring is ideal, and there can't be net force on it, so it will apply same force on both side. But why should the potential energy be measured individually rather taking the sum of total compressed/stretched distance from both sides?