This is similar to another StackExchange post (right down to the Kerbal Space Program mentions), but with a different approach. The question I'm trying to solve is thus:
Given current orbital state vectors for position ($\overrightarrow{r}$) and velocity ($\overrightarrow{v}$) (and it's safe to assume all of the current orbit's Keplerian elements are known as well), I am attempting to determine the $\Delta v $ required to reach a target apoapsis $R_{a}$. The location in the orbit is arbitrary; it might not be at apoapsis or periapsis; thus the target semi-major axis $a$ and eccentricity $e$ are not known and using the Vis-viva equation for the target semi-major axis isn't an option by itself.
In my particular case, I've added a constraint that the direction of $\overrightarrow{v}$ will not change -- only its magnitude. In other words, the resulting burn will be along the prograde/retrograde vector, and I'm essentially only trying to determine the magnitude of said vector.
My idea was to use a small portion of the formulas for programatically calculating orbital elements using position/velocity vectors in reverse -- namely those involving eccentricity and semi-major axis -- and then solve the resulting equation for the magnitude of $\overrightarrow{v}$. To do this, I replaced $\overrightarrow{v}$ with $\overrightarrow{d}m$, where $d$ is the normalized current velocity vector and m its magnitude. The resulting formula, after some simplification, looks like this:
$$ R_{a} = \frac{\mu + 1+|(m-g)\overrightarrow{r} - \overrightarrow{d}(\overrightarrow{r}\cdot\overrightarrow{d})m|}{2g-m} $$ where $m$ is the magnitude of $\overrightarrow{v}$ squared and $g = \frac{\mu}{|\overrightarrow{r}|}$. This definition of $g$ is technically wrong but works for this equation -- more on that in a minute.
This equation gives me a formula that correctly determines my current apoapsis when I toss in the other parameters. However, I couldn't figure out how to solve it for $m$ on my own... so I asked Wolfram Alpha, which gives me the following: $$ m = \frac{2ag+gr-\mu-1}{a-dr\cdot r + r} $$ or $$ m = \frac{2ag-gr-\mu-1}{a+dr\cdot r + r} $$ (I couldn't find a way to convince it that $d$ and $r$ were vectors; thus they are not shown as such here. $r$ is $R_{a}$).
Plugging the numbers back into this formula, however, yielded incorrect results. But!
I found that if I used the "correct" formula for $g$ ($g = \frac{\mu/}{|\overrightarrow{r}|^2}$), it would yield completely wrong values for the apoapsis given other known variables... but plugging that 'wrong' apoapsis in to the other formula ended up yielding the correct value for $m$ for the 'correct' apoapsis. That said, I have no idea how to take advantage of that fact -- and I'm at a loss at where to continue from here after poking at it for several days.
So, a few questions:
What am I missing here?
Is there some other method to solving this that I'm not missing? I considered something involving conservation of angular momentum, but ran into the same problem where the formulas I could find require knowing the semi-major axis value.