Let $u$ and $v$ be nonzero column vectors of size $n$ and consider the $n \times n$ positive-definite matrix $A:=uu^T + vv^T$. In this post https://math.stackexchange.com/a/112201/168758, the eigenvalues of $A$ were computed analytically.
Question
I wonder whether there is an analytic formula for the eigenvectors of $A$.
Observation
This answer https://math.stackexchange.com/a/112197/87355 shows how to compute the eigenvalues of $A$ via 2 iterations of Gram-schmidt. The method also contains a blueprint for computing the eigenvectors, in principle. The issue is that this method gives an eigendecomposition in a basis $\mathcal B=\{u_1,u_2,\ldots\}$ which is different from the standard basis. With all of this in hand, how to get eigenvectors of $A$ in the standard basis efficiently (for example, without computing the other $n-2$ vectors $u_3,\ldots,u_n$ of the basis $\mathcal B$, and then doing a change of basis formula).
Update
Fibonatic's answer along with the refs above, here is some python code which solves the problem (hope it helps someone else):
def special_eig(u, v, tol=1e-9):
"""
Computes leading eigenvalue and eigenvector of uu^T + vv^T
Notes
=====
Many of the computations can become numerically unstable. Most of the code
is to overcome these potential issues.
"""
from math import sqrt
u2 = u.dot(u)
v2 = v.dot(v)
uv = u.dot(v)
# check for linear dependence
if u2 <= tol:
return v2, v
if v2 <= tol:
return u2, u.copy()
tmp = uv ** 2 / (u2 * v2)
if abs(tmp - 1) <= tol:
return u2 + v2, u.copy()
# at this point, u and v are linear independent
disc = sqrt((u2 - v2) ** 2 + 4 * (uv) ** 2)
eigval = .5 * (u2 + v2 + disc)
if abs(uv) <= tol:
x = uv / (eigval - v ** 2)
else:
x = (eigval - u2) / uv
eigvec = u + x * v
return eigval, eigvec