I'm trying to calculate the 'instantaneous' semi-major axis of a binary system with two equal (known) mass stars for an $N$-body simulation. I know their velocities and positions at a given time, but am unsure how best to calculate the semi-major axis. I tried using the vis-viva equation
$$v^2 ~=~ G(M_1 + M_2)\cdot(2/r - 1/a) $$
However I'm not sure if $r$ should be the distance between the two masses or the distance to the centre of mass and whether the $M$'s should be the masses or the sum and the reduced mass? Whatever I try the semi-major axis seems to oscillate over the orbit at around the correct value, but surely it should be constant? Any advice would be brilliant, thanks.
edit: Not allowed to answer my own question yet, but I'm an idiot and wasn't doing relative velocities, thanks guys.