If \( A \) is a positive semi-definite matrix, then the set of all \( x \) such that \( x'Ax=c \), where \( c\geq 0 \) is an ellipsoid. If \( A \) is a \( 2\times 2 \) matrix this is an ellipse in the plane.
The set of all \( x \) such that \( x'x=1 \) is the unit sphere, in the plane the unit circle.
Now consider the problem, in the plane, of finding the largest and the smallest ellipse \( x'Ax=c \) that intersect the unit circle. This is also the problem of finding the maximum and minimum of \( f(x)=x'Ax \) over \( x \) satisfying \( x'x=1 \). The maximum is the largest eigenvalue of \( A \) and the corresponding maximizer \( x \) is the largest eigenvector. And similarly for the minimum, which gives the smallest eigenvalue and the correspinding eigenvector. The two eigenvectors are orthogonal and correspond with the principal axes of the ellipse.
The ellipse
package in R
makes it easy to draw ellipses in the plane.
library(ellipse)
We use the function ellipse()
with the two parameters
r
and t
, where \( -1\leq r\leq +1 \). Parameter r
is the correlation parameter, which is used to form a correlation matrix
\[
R=\begin{bmatrix}1&r\\r&1\end{bmatrix}.
\]
The function then computes 100 points on the ellipse \( x'R^{-1}r=t^2 \), and these can be plotted in the usual way. Now \[ R^{-1}=\frac{1}{1-r^2}\begin{bmatrix}1&-r\\-r&1\end{bmatrix}. \] The two eigenvalues of \( R^{-1} \) are \( \frac{1}{1+r} \) and \( \frac{1}{1-r} \), with the corresponding eigenvectors proportional to \( (+1,+1) \) and \( (+1,-1) \).
plotEllipse <- function(r) {
u <- sqrt(1/c(1 + r, 1 - r))
s <- sqrt(2/(1 + r))
plot(ellipse(0, t = 1), xlim = c(-2, 2), ylim = c(-2, 2), type = "l", asp = 1,
lwd = 3, col = "BLUE")
for (t in seq(u[2], u[1], length = 20)) {
lines(ellipse(r, t = t), col = "RED")
text(t/s, t/s, format(t, digits = 2), cex = 0.7)
}
abline(0, 1)
abline(0, -1)
}
plotEllipse(0.5)
plotEllipse(0.9)
plotEllipse(0.1)
plotEllipse(-0.3)