Solution (source code)

= Solution

The second <gradient> is $\nabla_v b=[A+B-(\alpha+\beta)I]v$. Combining its vanishing with $(A-\alpha I)v=0$ gives
$$
\boxed{v\in\ker(A-\alpha I)\cap\ker(B-\beta I).}
$$
The zero vector always works. A nonzero common stationary vector exists exactly when $A,B$ have a common <eigenvector> with respective <eigenvalues> $\alpha,\beta$; both stationary values are then zero. <Commuting symmetric matrices have a common orthonormal eigenbasis>, so commutation is sufficient to find such vectors for the paired <eigenvalues> in that basis. It does not guarantee an arbitrary prescribed pair.

Commutation is also not necessary for one common <eigenvector>. For example,
$$
A=\operatorname{diag}(1,2,3),\qquad B=\begin{pmatrix}\beta&0&0\\0&0&1\\0&1&0\end{pmatrix}
$$
are real <symmetric matrices> sharing $e_1$ with <eigenvalues> $1,\beta$, but $AB\ne BA$. This separates the question's common-vector condition from the stronger <simultaneous diagonalization> of the entire space.