# How to solve an equation containing a matrix and its inverse using least-squares?

I've encountered a problem that needs to be solved by solving the following algebraic equation

$$\mathbf{Y}^\mathsf{T}\mathbf{Q}\mathbf{Y}=\mathbf{X}^\mathsf{T}\mathbf{Q}^\mathsf{-1}\mathbf{X}$$

where $$Q$$ is a $$4 \times 4$$ symmetric matrix to be solved. $$X$$ and $$Y$$ are both known $$4 \times 1$$ vectors. There are enough $$X$$ and $$Y$$ inputs so that I think a nonlinear least-squares solution must be existed. However, I can not figure it out by myself. Hope you could provide me with some clues.

• What do you mean by "the equation needs to be solved"? Do you need a parameterization of every possible solution? Jan 7 '20 at 12:24
• My friend, you have one relation and $10$ unknowns!! On the other hand, it's not a linear equation in $Q$. That is not serious...
– user91684
Jan 7 '20 at 19:04
• Actually,Q is an ellipsoid, X is the point on the ellipsoid, and Y is the plane tangent to the ellipsoid. I hope to turn this equation into least square solution @Omnomnomnom Jan 8 '20 at 1:47
• Actually,Q is an ellipsoid, X is the point on the ellipsoid, and Y is the plane tangent to the ellipsoid.X and Y have enough inputs so we can construct more than 10 equations.I hope to turn this equation into least square solution @loupblanc Jan 8 '20 at 1:48
• I am not sure how to interpret "X is the point on the ellipsoid, and Y is the plane tangent to the ellipsoid". I think that you are trying to say that $X$ is a point on the ellipsoid, and that the tangent plane to the ellipsoid is the solution set for $Z$ of the equation $Y^TZ = Y^TX$. Is this correct? Jan 8 '20 at 2:22

I think you can use $$\operatorname{vec}$$ operator for constructing a least squares problem. But I'm not sure it would produce a consistent answer.

\begin{align*} \operatorname{vec}(y^TQy) &= \operatorname{vec}(x^TQ^{-1}x) \\ (y^T \otimes y^T) \operatorname{vec}(Q) &= (x^T \otimes x^T) \operatorname{vec}(Q^{-1}) \end{align*}

So, you can write this as

$$\begin{bmatrix}(y_1^T \otimes y_1^T) & -(x_1^T \otimes x_1^T) \\ \vdots & \vdots \\ (y_N^T \otimes y_N^T) & -(x_N^T \otimes x_N^T) \end{bmatrix} \begin{bmatrix} \operatorname{vec}(Q) \\ \operatorname{vec}(Q^{-1}) \end{bmatrix} = 0$$

for $$N$$ data you have. From this point the problem becomes finding the null space of the known matrix and selecting the set of vectors such that $$Q Q^{-1} \approx I$$.

• Excuse me,$Q$ is an ellipsoid,But is $Q^{-1}$ also an ellipsoid? Because if $Q^{-1}$ is represented by the parameters of $Q$, $Q^{-1}$ is very complicated.@obareey Jan 10 '20 at 2:13
• This solution doesn't assume any relation between $Q$ and $Q^{-1}$. This is why it may produce inconsistent results, because the solution most likely is not unique. Jan 10 '20 at 7:21

Presumably the underlying field is real. There are infinitely many solutions but I think the easiest ones are the followings:

1. If both $$X$$ and $$Y$$ are nonzero, set $$Q=\frac{\|X\|}{\|Y\|}I$$.
2. If $$X=Y=0$$, set $$Q=I$$.
3. If $$X=0\ne Y$$, extend $$y=\frac{Y}{\|Y\|}$$ to an orthonormal basis $$\{y,u,v,w\}$$ of $$\mathbb R^4$$. A solution is given by $$Q=Q^{-1}=yu^T+uy^T+vv^T+ww^T$$.
4. If $$X\ne0=Y$$, extend $$x=\frac{X}{\|X\|}$$ to an orthonormal basis $$\{x,u,v,w\}$$ of $$\mathbb R^4$$. A solution is given by $$Q=Q^{-1}=xu^T+ux^T+vv^T+ww^T$$.

a) I propose this (very elementary) method. I assume that all the matrices are real.

i) Randomly choose a real symmetric matrix $$Q\in S_4$$; put $$Q[1,1]:=q,Q[1,2]:=r$$.

ii) Calculate $$p(q,r)=numer(Y^TQY-X^TQ^{-1}X)$$ (the numerator of the quotient); it's a polynomial of degree $$2$$ wrt $$q$$. Then $$d(r)=discrim(p,q)$$ (the discriminant of $$p$$ wrt $$q$$) is a polynomial of degree $$4$$ wrt $$r$$.

You easily obtain a solution in $$Q$$ if there is $$r_0$$ s.t. $$d(r_0)\geq 0$$.

iii) I tested $$30000$$ random values of the couple $$(X,Y)$$. In each case, $$d(0)>0$$. Anyway, if your random $$Q$$ is not convenient, then choose another $$Q$$!

If you have a problem with some $$(X,Y)$$, then write me. Now, it's up to you to work.

EDIT. b) $$\textbf{Proposition}$$. If for every $$i$$, $$Y_i\not= 0$$, then there is at least a solution of $$(*)$$ $$Y^TQY=X^TQ^{-1}X$$.

$$\textbf{Proof}$$. We seek $$Q$$ in the form $$Q=diag(q_i)$$ where $$q_i\not= 0$$.

$$(*)$$ can be rewritten $$\sum_i(q_iY_i^2-\dfrac{1}{q_i}X_i^2)=0$$. We choose $$q_i=X_i/Y_i$$.

$$\textbf{Remark}$$. After reflexion, I think that there are solutions in any cases. For example, if $$Y=0,X=[1,0,\cdots,0]^T$$, then a solution is

$$Q=\begin{pmatrix}1&1&1&1\\1&2&1&1\\1&1&3&1\\1&1&1&3/5\end{pmatrix}$$.