Is every linear projection orthogonal with respect to some inner product?

For example, for any given idempotent matrix $P^2=P\in \mathbb{R}^{n\times n}$, is there always a symmetric, positive-definite matrix $A$ such that \begin{aligned} \langle Px,y\rangle_A=x'P'Ay=x'APy=\langle x,Py\rangle_A \end{aligned} for all $x,y\in \mathbb{R}^n$? Does it generalize to arbitrary inner product spaces?

Yes. Let $V = \ker P$ and $W = P(\mathbb{R}^n)$. Let $\{v_1,\dots,v_k\}$ be a basis of $V$ and $\{w_1,\dots,w_m\}$ be a basis of $W$. Then $\{v_1,\dots,v_k,w_1,\dots,w_m\}$ is a basis of $\mathbb{R}^n$. Define the inner product $\langle\langle.,.\rangle\rangle$ satisfying that \begin{eqnarray*} \langle\langle v_i,v_j\rangle\rangle &=& \delta_{ij}\\ \langle\langle w_i,w_j\rangle\rangle &=& \delta_{ij}\\ \langle\langle v_i,w_j\rangle\rangle &=& 0. \end{eqnarray*} We know there is a matrix $A$ such that $\langle\langle.,.\rangle\rangle = \langle.,.\rangle_{A}$. Because $\langle\langle.,.\rangle\rangle$ is an inner product we must have that $A$ is symmetric and positive-definite. Moreover it follows that $$\langle Px,y\rangle_A = \langle x,Py\rangle_A$$ as can be easily checked.
• Can you be more precise? You want to replace $\mathbb{R}^n$ with a Hilbert space or a general infinite dimensional space? – João Caminada Mar 26 '17 at 22:13
• Yeah, I was thinking a Hilbert space. Although I guess I don't know enough about Hilbert spaces to know if they have the same property where you can translate between inner products with linear transformations, so that $\langle \cdot,\cdot\rangle_1=\langle \cdot,T(\cdot)\rangle_2$ for some linear transformation $T$. – user385013 Mar 26 '17 at 23:40