We can find the change in potential energy of our system by measuring the work done by our weights as they move up and down. If we consider that $x_1$ and $x_2$ increase as the weights move down, the work done by the $x_1$ weight is given by: $$W_1 = \int F_1 dx_1$$ Similarly, the work done by the $x_2$ weight is given by: $$W_2 = \int F_2 dx_2$$ Taken together, we can see that the change in the potential energy of our system must be given by the sum of these two changes in energy, which comes out to: $$\Delta U = \int F_1 dx_1 + \int F_2 dx_2$$
Work and heat
We can find the potential energy in a spring by integrating to find the work done… provided we know the Hook's law, which tells us the force due to a spring. $$W = \int F dx$$ $$= \int kx dx$$ $$= k \int_0^x x dx$$ $$= \frac12 k x^2$$ As we shall see next week, heat is another way of getting energy into or out of a system, just like work.