# Thread: Sketching an Ellipsoid using a matrix

1. ## Sketching an Ellipsoid using a matrix

How would I sketch the ellipsoids $\displaystyle x^t \Sigma^{-1} x <= 1$ for

$\displaystyle \Sigma =\begin{bmatrix}5 &4\\ 4 &5\end{bmatrix}$ and $\displaystyle \Sigma=\begin{bmatrix}3 & 0\\ 0 &3\end{bmatrix}$

clearly indicating the principal axes of the ellipsoid and the intersection of the ellipoids with the axes.

I know that the equation for an ellipsoid $\displaystyle \frac{x^2}{a} + \frac{y^2}{b} + \frac{z^2}{c} = 1$ but not sure how or if it even applies in this problem.

Any help would be greatly appreciated.

2. Are you after the confidence ellipsoid for $\displaystyle \mu$

$\displaystyle \displaystyle n(\bar{x}-\mu)^TS^{-1}(\bar{x}-\mu) \leq \frac{p(n-1)}{n-p}\times F_{p,n-p,\alpha}$

?

3. The matrix $\displaystyle \Sigma= \begin{bmatrix}5 & 4 \\ 4 & 5 \end{bmatrix}$ has eigenvalues 9 and 1 with corresponding eigenvectors $\displaystyle \begin{bmatrix}1 \\ 1\end{bmatrix}$ and $\displaystyle \begin{bmatrix}1 \\ -1\end{bmatrix}$ respectively. If we let $\displaystyle P= \begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}$, the matrix having those eigenvalues as columns, then $\displaystyle P^{-1}=\begin{bmatrix}\frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2}\end{bmatrix}$ and $\displaystyle P^{-1}\Sigma P= \begin{bmatrix}\frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2}\end{bmatrix}\begin{bmatrix}5 & 4 \\ 4 & 5 \end{bmatrix}\begin{bmatrix}1 & 1 \\ 1 & -1\end{bmatrix}= \begin{bmatrix}9 & 0 \\ 0 & 1\end{bmatrix}$, a diagonal matrix having the eigenvalues of $\displaystyle \Sigma$ on its diagonal.

Blast! I did this whole thing without realizing it was $\displaystyle \Sigma^{-1}$ you wanted rather than $\displaystyle Sigma$! Fortunately, we can still use all of that. If $\displaystyle P^{-1}\Sigma P= \begin{bmatrix}9 & 0 \\ 0 & 1\end{bmatrix}$, then taking the inverse of both sides, $\displaystyle P^{-1}\Sigma^{-1}P= D^{-1}= \begin{bmatrix}\frac{1}{9} & 0 \\ 0 & 1\end{bmatrix}$. And so $\displaystyle P\begin{bmatrix}\frac{1}{9} & 0 \\ 0 & 1\end{bmatrix}P^{-1}= \Sigma^{-1}$

The original equation was $\displaystyle x^T\Sigma^{-1}x= 1$. Which is the same as $\displaystyle x^T(P\begin{bmatrix}\frac{1}{9} & 0 \\ 0 & 1\end{matrix}P^{-1}x= 1$. Let $\displaystyle x'= P^{-1}x$ so that $\displaystyle x'^T= (P^{-1}x)^T= x^TP$ and the equation becomes $\displaystyle x'^T\begin{bmatrix}\frac{1}{9} & 0 \\ 0 & 1\end{bmatrix}x'= 1$.

If $\displaystyle x'= \begin{bmatrix}x' \\ y'\end{bmatrix}$ then that equation is $\displaystyle \frac{x'^2}{9}+ y'^2= 1$. That is an ellipse with axis of length 1/3 along the x'-axis and matrix of length 1 along the y' axis. That choice for x' means that the x'-axis is the same as the y= x line and the y' axis is the same as the y= -x line.

Summarizing, since the original ellipse, $\displaystyle \Sigma^{-1}$, has eigenvalues 1/3 and 1, with eigenvectors <1,1> (along the y= 1 line) and <1, -1> (along the y= -x line), respectively, the ellipse has semi-minor axis of length 1/3 along the line y= x and semi-major axis of length 1 along the y= -x line. The center is still at (0, 0), of course.

By the way, since this is in two dimensions, this is an ellipse, not an ellips[b]oid[b]. An "ellipsoid" is the three dimensional analog of the ellipse.

$\displaystyle \Sigma= \begin{bmatrix}3 & 0 \\ 0 & 3\end{bmatrix}$ has determinant 0 and so does NOT have an inverse.

4. Thanks for your help HallsofIvy. Just got a quick question. What's the different between semi-minor axis and semi-major axis? Is the major bigger than the minor?

$\displaystyle \Sigma= \begin{bmatrix}3 & 0 \\ 0 & 3\end{bmatrix}$ should have determinant 9 (not 0) and the inverse should exist. So would I apply the same process as the first matrix (even though this matrix only has 1 eigenvalue)?

5. Originally Posted by statmajor
Thanks for your help HallsofIvy. Just got a quick question. What's the different between semi-minor axis and semi-major axis? Is the major bigger than the minor?
Yes, that's the only difference.

$\displaystyle \Sigma= \begin{bmatrix}3 & 0 \\ 0 & 3\end{bmatrix}$ should have determinant 9 (not 0) and the inverse should exist. So would I apply the same process as the first matrix (even though this matrix only has 1 eigenvalue)?
For some reason, I was seeing $\displaystyle \Sigma= \begin{bmatrix}3 & 0 \\ 3 & 0\end{bmatrix}$.

Actually, you don't need to go through that process- basically, I was "diagonalizing" the matrix and this matrix is already diagonal. Not every 2 by 2 matrix having only one eigenvalue can be diagonalized- it depends on the number of independent eigenvectors. (Every symmetric matrix can be diagonalized.)

Here, 3 is the eigenvalue and independent eigenvectors are given by <1, 0> and <0, 1>, along the x and y axes. $\displaystyle \Sigma^{-1}= \begin{bmatrix}\frac{1}{3} & 0 \\ 0 & \frac{1}{3}\end{bmatrix}$ and if we write $\displaystyle = x= \begin{bmatrix}x \\ y \end{bmatrix}$, then $\displaystyle x^T\Sigma^{-1}x= \begin{bmatrix}x & y\end{bmatrix}\begin{bmatrix} \frac{1}{3} & 0 \\ 0 & \frac{1}{3}\end{bmatrix}\begin{bmatrix}x \\ y\end{bmatrix}$$\displaystyle = \frac{x^2}{3}+ \frac{y^2}{3}= 1$ or $\displaystyle x^2+ y^2= 3$. That "ellipse" is actually a circle with center at (0, 0) and radius $\displaystyle \sqrt{3}$.

6. Just wondering what the point of diagonilzing the matrix is. Couldnt I just find the inverse of the matrix, let x = (y x) and just plug it back into the equation $\displaystyle x^t \Sigma^{-1} x <= 1$?

7. Originally Posted by statmajor
Just wondering what the point of diagonilzing the matrix is. Couldnt I just find the inverse of the matrix, let x = (y x) and just plug it back into the equation $\displaystyle x^t \Sigma^{-1} x <= 1$?
The point is to get the equation in "standard form" for an ellipse:
$\displaystyle \frac{x^2}{a^2}+ \frac{y^2}{b^2}=$ is an ellipse with sem-axis of length a along the x- axis and semi-axis of length b along the y axis.

With $\displaystyle \Sigma= \begin{bmatrix}5 & 4 \\ 4 & 5\end{bmatrix}$, $\displaystyle Sigma^{-1}= \begin{bmatrix}\frac{5}{9} & -\frac{4}{9} \\ -\frac{4}{9} & \frac{5}{9}\end{bmatrix}$ so that, taking $\displaystyle x= \begin{bmatrix}x\\ y\end{bmatrix}$, $\displaystyle x^t\Sigma^{-1}x<= 1$ becomes
$\displaystyle \begin{bmatrix}x & y\end{bmatrix}\begin{bmatrix}\frac{5}{9} & -\frac{4}{9} \\ -\frac{4}{9} & \frac{5}{9}\end{bmatrix}\begin{bmatrix}x \\ y \end{bmatrix}= \frac{5}{9}x^2- \frac{8}{9}xy+ \frac{5}{9}y^2\le 1$.

That "xy" term signals an ellipse whose axes are NOT along the x and y axes.

By determining the eigenvectors for the matrix, as I did before, you see that the axes are the lines y= x and y= -x.

A more tedious, less sophisticated, way of doing the same thing would be to let $\displaystyle x= x'cos(\theta)- y sin(\theta)$ and $\displaystyle y= x' sin(\theta)+ y' cos(\theta)$ in the equation of the ellipse, $\displaystyle \frac{5}{9}x^2- \frac{8}{9}xy+ \frac{5}{9}y^2= 1$, then determine $\displaystyle \theta$ to make the coefficient of x'y' equal to 0. You should get $\displaystyle \theta= \pi/4$.