# Expression for total potential energy in coupled systems

I was reading through applications of Lagrangian mechanics and the case of coupled oscillators. The example provided is the famous two pendula length $$l$$ mass $$m$$ hanging from the ceiling connected by a spring with spring constant $$k$$. We call their angles $$\theta_1$$ and $$\theta_2$$ as measured from the vertical. The total kinetic energy of the system is:

$$T = \frac{1}{2}mv_1^2+\frac{1}{2}mv_2^2=\frac{1}{2}ml^2(\dot{\theta_1}^2+\dot{\theta_2}^2)$$ Meanwhile the potential energy can be found to be: $$U = mgl(1-\cos \theta_1) + mgl(1-\cos \theta_2)+ \frac{1}{2}k(l\sin \theta_2- l\sin \theta_1)^2$$ Where we get this from the fact that thw horizontal position of each bob is $$x_i= l\sin \theta_i$$. Then we get the Lagrangian by $$L=T-U$$ and the equations of motion from the Euler-Lagrange equation, etc.

My question relies on how this potential energy is found. Of course there are two contributions to the potential energy: the gravitational potential energy and the spring potential energy. The total gravitational potential energy is the sum of each bob's gravitational potential energy as we see in $$U$$.

However, the spring potential energy seems weird to me. We know that $$\frac{1}{2}kx^2$$ gives the spring potential energy for a particle connected to a spring displaced by a distance $$x$$ from equilibrium. However this is the energy for each particle, so (I don't know if this question is too stupid, but) why is the total spring potential energy equal to $$\frac{1}{2}k(x_2-x_1)^2$$ and not the sum of the two, which would be $$\frac{1}{2}k(x_2-x_1)^2+\frac{1}{2}k(x_1-x_2)^2 =k(x_2-x_1)^2$$ Of course the first one is right since it gives the correct EOMs, but can anyone provide an explanation on why we take just one of the potential energy contributions and not the two? Why would the second one be "overcounting"?

The potential energy of the "spring" is solely attributed to the elongation of the spring (and it's intrinsic to the spring) independent of whether the spring was attached to bobs on either sides or a wall and a bob on one side. So given that the sping has a spring constant k, it's potential energy is indeed $$\frac{1}{2}k(x_1-x_2)^2$$ where the elongation of the spring is $$x_1-x_2$$. Hope that helps.
We know that $$\frac12kx^2$$ gives the spring potential energy for a particle connected to a spring displaced by a distance 𝑥 from equilibrium.
In the coupled system, the spring is between the two pendulums, and we assume equilibrium is when they are at the same angle. If the pendulums swing in a way to move them either closer together or further apart, then energy is placed in the spring. If both pendulums have the same displacement of $$x$$, then the spring is still at equilibrium. So the total spring extension or compression is equal to the difference in the motion of the two pendulums.