How to solve the following matrix equation? $$A+BX^{-1}B=X$$
where $A$ is a square matrix and Hermitian, $B=B^T$ and $B$ has real entries. I want to find the square matrix $X$. If an analytic solution does not exist, a numerical solution will also suffice. Furthermore, can we find the properties of X from this equation? I encountered this equation trying to equate two exponentials:
$$\exp\left[z^T\left(A+BX^{-1}B\right)z\right]=\exp\left(z^TXz\right)$$
where $z$ is a real column matrix.
 A: If $B$ happens to be invertible, you may put $C=AB^{-1},\,Y=XB^{-1}$ and rewrite the equation as $C+Y^{-1}=Y$. Hence every solution $Y$ must commute with $C$ and $Y^2-CY-I=0$. It follows that
$$
Y=\frac{C+\sqrt{C^2+4I}}{2}
$$
where $\sqrt{C^2+4I}$ some matrix square root of $C^2+4I$. If you can find one such square root that commutes with $C$ and makes $Y$ invertible, then $X=YB$ is indeed a solution to the original equation. In particular, if $C$ is a diagonalisable matrix with a real spectrum, you may simply pick the "natural" square root $PD^{1/2}P^{-1}$, where $C^2+4I=PDP^{-1}$ is an eigendecomposition and $D^{1/2}$ is the entrywise square root of $D$.
Remark. There is actually no need to solve the matrix equation $A+BX^{-1}B=X$, because it suffices to solve
$$
z^T\left(A+BX^{-1}B\right)z=z^TXz.\tag{1}
$$
If $z^TAz\ne0$ or $Bz\ne0$, the quadratic equation $\|z\|^2x^2-(z^TAz)x-\|Bz\|^2=0$ has a nonzero root $x=\frac12\left(z^TAz+\sqrt{(z^TAz)^2+4\|z\|^2\|Bz\|^2}\right)$. Hence we may take $X=xI$.
If $z^TAz=0$ and $Bz=0$ but $z\in\mathbb R^n$ is nonzero, extend $\{z\}$ to an orthogonal basis $\{z,u,v_3,v_4,\ldots,v_n\}$ of $\mathbb R^n$. Let $Y=\pmatrix{u+z&u-z&v_3&\cdots&v_n}$. Then $X=YY^T$ is an invertible matrix that solves $(1)$.
If $z=0$, any invertible $X$ will solve $(1)$.
