Convert Covariance Matrix to Quadric Ellipsoid Form

algebraic-geometrygeometrylinear algebra

Question:
I have a 3×3 covariance matrix $M$ which I can plot in 3D to an ellipsoid (by eigendecomposition to get the principal axes and the scales).
What I want is to project this covariance matrix onto the $XY$ plane. How can I do this?

Background:
My question is related to this question. In fact, I'm trying to use this answer to project my covariance matrix $M$ onto the $XY$ plane.

I understand that what I need to do is to represent the ellipsoid as its quadric matrix form, then use the projection matrix $P$ below to project:

$$\mathtt P = \begin{bmatrix}1&0&0&0\\0&0&1&0\\0&0&0&1\end{bmatrix}$$

What I'm struggling with is how to convert my covariance matrix $M$ to the ellipsoid's quadric form. The covariance matrix itself is an ellipsoid, but I'm not sure I can use it directly with the approach in the answer linked above.

Wikipedia says $x^TAx=1$ would represent an arbitrary ellipsoid centered at the origin. However, it says eigenvalues of $A$ are "reciprocals of the squares of the semi-axes". Does this mean I have to do eigendecomposition of $M$, then rebuild $A$ from that? Also, the general quadric matrix $A$ is 4×4 but my covariance is 3×3, so not sure what to put in the remaining elements of $A$.

I guess a more general question would be, what is the relationship between $M$ and $A$?

Best Answer

TL;DR: Just add zeros.

The general quadric equation can be broken down into the sum of a quadratic form, a linear term and a constant: $$\mathbf x^T\mathtt A\mathbf x+2\mathbf b^T\mathbf x+c=0.$$ The coefficients can be packaged up into a single homogeneous matrix $\mathtt Q$ by setting $\hat{\mathbf x}=(\mathbf x^T; 1)^T$ so that the equation becomes $$\hat{\mathbf x}^T\mathtt Q\hat{\mathbf x} = \begin{bmatrix}\mathbf x&1\end{bmatrix} \begin{bmatrix}\mathtt A & \mathbf b \\ \mathbf b^T & c\end{bmatrix} \begin{bmatrix}\mathbf x\\1\end{bmatrix} = 0.$$ (This equation is homogeneous in the components of $\hat{\mathbf x}$, so we can relax the restriction that the last component be $1$.)

For your covariance matrix, the ellipsoid equation is $\mathbf x^T\mathtt M\mathbf x=1$, therefore $\mathbf b=0$ and $c=-1$, i.e., $$\mathtt Q = \begin{bmatrix}\mathtt M & \mathbf 0 \\ \mathbf 0^T & -1\end{bmatrix}.$$ The projection matrix $\mathtt P$ for orthogonal projection onto the $x$-$y$ plane simply deletes the third component of a vector, so the matrix $\mathtt C$ that represents the projected outline of the ellipsoid will also have this form, but with a $2\times2$ matrix $\mathtt M'$. Computing the matrix of the outline thus comes down to inverting the upper-left $2\times2$ submatrix of $\mathtt M^{-1}$ and the Cartesian equation of the resulting ellipse is $(x,y)\,\mathtt M'(x,y)^T=1$. If you’re so inclined, you could even develop a closed-form formula for the coefficients of this equation from $\mathtt M^{-1}=\operatorname{cof}(M)^T/\det(M)$. The resulting expressions turn out to be quite simple.