Two-by-two positive-definiteness test (source code)

= Two-by-two positive-definiteness test
{title2=$a>0,\quad ac-b^2>0$}

For a real <symmetric matrix> $A=\begin{pmatrix}a&b\\b&c\end{pmatrix}$, <completing the square> gives, when $a\ne0$,
$$
q(x,y)=ax^2+2bxy+cy^2=a\left(x+\frac ba y\right)^2+\frac{ac-b^2}{a}y^2.
$$
Thus $A$ is a <positive-definite matrix> exactly when $a>0$ and $\det A=ac-b^2>0$. For necessity, test $(1,0)$ first, then $(-b/a,1)$; for sufficiency, the displayed two positive squares give the result. These are the first two leading <principal minors> in <Sylvester's criterion>. A positive <determinant> alone is insufficient: $-I_2$ has <determinant> $1$ but is a <negative-definite matrix>.

The <eigenvalues> provide an equivalent test under the same real-symmetric hypothesis:
$$
\lambda_\pm=\frac{a+c\pm\sqrt{(a-c)^2+4b^2}}2,\qquad A\text{ positive definite}\ \Longleftrightarrow\ \lambda_+>0\text{ and }\lambda_->0.
$$
The <spectral theorem for real symmetric matrices> supplies <coordinates> in an <orthonormal basis> in which $q=\lambda_+u^2+\lambda_-v^2$. More generally, a complex <Hermitian matrix> has an <orthonormal eigenbasis> and $q(z)=\sum_j\lambda_j|w_j|^2$, so it is a <Hermitian positive-definite matrix> exactly when every <eigenvalue> is positive. This is a short proof outline: test the <eigenvectors> for necessity, and sum the positive squared <absolute values> for sufficiency.<Convex Optimization by Stephen Boyd and Lieven Vandenberghe>[Appendix A.5.2, pp. 646–647: symmetric eigenvalue decomposition and definiteness]{ref}

For a real <positive semidefinite matrix>, the condition is instead $q(x,y)\geq0$ for all <vectors>, equivalent here to $a\geq0$, $c\geq0$, and $ac-b^2\geq0$. If $a>0$, the same <completing the square> proves this; if $a=0$, nonnegativity forces $b=0$ and leaves $cy^2$ with $c\geq0$. Merely replacing the strict inequalities on the leading <principal minors> by nonstrict ones fails: $\operatorname{diag}(0,-1)$ has both leading <principal minors> zero yet gives $q(0,1)=-1$. An <indefinite quadratic form> takes both positive and negative values; its real <symmetric matrix> has <eigenvalues> of both signs.