SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 3.7.1 Quadratic forms and positive definitenessConcept · 35 min
      2. 3.7.2 The Cholesky factorisationConcept · 30 min
      3. 3.7.3 Practice set: positive definitenessPractice set · 20 min
      4. 3.7.4 Case study: valid correlation matrices and correlated simulationCase study · 35 min

Level 3, Linear algebra 3.7 Positive definiteness and Cholesky Lesson 1 of 4

ConceptLesson 3.7.1 in Level 3, Linear algebra. About 35 minutes.

Quadratic forms and positive definiteness

What a quadratic form is

Lesson 3.2.3 multiplied a row, a square matrix and a column to get one number. Use the same vector on both sides and the result is a quadratic form. For a symmetric n×nn \times n matrix AA and a vector x\mathbf{x} in Rn\mathbb{R}^n, it is

q(x)=x⊤A xq(\mathbf{x}) = \mathbf{x}^\top A\,\mathbf{x}

The shapes are (1×n)(n×n)(n×1)(1 \times n)(n \times n)(n \times 1), so q(x)q(\mathbf{x}) is a single number. It is called quadratic because every term multiplies two components of x\mathbf{x}.

Write it out for A=(abbc)A = \begin{pmatrix} a & b \\ b & c \end{pmatrix} and x=(x1,x2)\mathbf{x} = (x_1, x_2). First Ax=(ax1+bx2, bx1+cx2)A\mathbf{x} = (ax_1 + bx_2,\ bx_1 + cx_2), then the dot product with x\mathbf{x}:

q(x)=x1(ax1+bx2)+x2(bx1+cx2)=ax12+2bx1x2+cx22\begin{aligned} q(\mathbf{x}) &= x_1(ax_1 + bx_2) + x_2(bx_1 + cx_2) \\ &= ax_1^2 + 2bx_1x_2 + cx_2^2 \end{aligned}

The diagonal entries multiply the squares. The off-diagonal entry bb appears twice, once in each corner, so the cross term is 2bx1x22bx_1x_2.

Rule: Quadratic form

q(x)=x⊤A x=∑i∑jaij xi xjn=2: ax12+2bx1x2+cx22\begin{gathered} q(\mathbf{x}) = \mathbf{x}^\top A\,\mathbf{x} = \textstyle\sum_i\sum_j a_{ij}\,x_i\,x_j \\[4pt] n = 2:\ ax_1^2 + 2bx_1x_2 + cx_2^2 \end{gathered}

A symmetric matrix AA turns each vector x\mathbf{x} into one number. The diagonal of AA gives the squared terms; each off-diagonal pair aij=ajia_{ij} = a_{ji} gives the cross term 2aijxixj2a_{ij}x_ix_j.

Take lesson 3.4.1's matrix A=(3112)A = \begin{pmatrix} 3 & 1 \\ 1 & 2 \end{pmatrix}, so q(x)=3x12+2x1x2+2x22q(\mathbf{x}) = 3x_1^2 + 2x_1x_2 + 2x_2^2. At x=(1,−1)\mathbf{x} = (1, -1), Ax=(2,−1)A\mathbf{x} = (2, -1) and x⊤Ax=2+1=3\mathbf{x}^\top A\mathbf{x} = 2 + 1 = 3; the formula gives 3−2+2=33 - 2 + 2 = 3 too.

x\mathbf{x}(1,0)(1, 0)(0,1)(0, 1)(1,1)(1, 1)(1,−1)(1, -1)(2,−1)(2, -1)(−1,3)(-1, 3)
q(x)q(\mathbf{x})32731015

Three facts follow from the formula:

  • Only the symmetric part counts. B=(3202)B = \begin{pmatrix} 3 & 2 \\ 0 & 2 \end{pmatrix} is not symmetric, but its cross term is (2+0)x1x2(2 + 0)x_1x_2, the same as AA's. Any square BB gives the form of 12(B+B⊤)\frac{1}{2}(B + B^\top), which is why quadratic forms use symmetric matrices.
  • Scaling x\mathbf{x} by cc scales qq by c2c^2. q(2,−2)=12=4×q(1,−1)q(2, -2) = 12 = 4 \times q(1, -1), and q(−x)=q(x)q(-\mathbf{x}) = q(\mathbf{x}). So the sign of qq depends only on the direction of x\mathbf{x}.
  • q(0)=0q(\mathbf{0}) = 0 for every AA.

With three or more components the double sum has a term for every pair (i,j)(i, j): case study 3.2.5 met it as the portfolio variance w⊤Σw\mathbf{w}^\top\Sigma\mathbf{w}.

Try it

q(A, x) is x @ A @ x. The loop checks the table against 3x12+2x1x2+2x223x_1^2 + 2x_1x_2 + 2x_2^2.

Then the non-symmetric BB gives the same value as AA at (2,−1)(2, -1), and its symmetric part is AA. The last line shows the scaling: q(2x)=4q(x)q(2\mathbf{x}) = 4q(\mathbf{x}) and q(−x)=q(x)q(-\mathbf{x}) = q(\mathbf{x}).

⌘/Ctrl + Enter runs the cell

Four kinds of symmetric matrix

The question that matters is the sign of q(x)q(\mathbf{x}) over all x≠0\mathbf{x} \neq \mathbf{0}. Four matrices show the possibilities:

A=(3112),J=(1111)N=(1221),−S=(−2−1−1−2)\begin{gathered} A = \begin{pmatrix} 3 & 1 \\ 1 & 2 \end{pmatrix}, \quad J = \begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix} \\[6pt] N = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}, \quad -S = \begin{pmatrix} -2 & -1 \\ -1 & -2 \end{pmatrix} \end{gathered}

Here S=(2112)S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} is lesson 3.2.3's symmetric matrix, and JJ has every entry 1.

x\mathbf{x}(1,0)(1, 0)(0,1)(0, 1)(1,1)(1, 1)(1,−1)(1, -1)(2,−1)(2, -1)
AA: 3x12+2x1x2+2x223x_1^2 + 2x_1x_2 + 2x_2^2327310
JJ: (x1+x2)2(x_1 + x_2)^211401
NN: x12+4x1x2+x22x_1^2 + 4x_1x_2 + x_2^2116−2-2−3-3
−S-S: −2x12−2x1x2−2x22-2x_1^2 - 2x_1x_2 - 2x_2^2−2-2−2-2−6-6−2-2−6-6

JJ's form is x12+2x1x2+x22=(x1+x2)2x_1^2 + 2x_1x_2 + x_2^2 = (x_1 + x_2)^2, a square: never negative, and 0 along the whole line x2=−x1x_2 = -x_1. NN is positive at (1,1)(1, 1) and negative at (1,−1)(1, -1).

Rule: Definite, semidefinite, indefinite

positive definite:x⊤Ax>0 for every x≠0positive semidefinite:x⊤Ax≥0 for every x\begin{gathered} \text{positive definite:} \\ \mathbf{x}^\top A\mathbf{x} > 0 \text{ for every } \mathbf{x} \neq \mathbf{0} \\[6pt] \text{positive semidefinite:} \\ \mathbf{x}^\top A\mathbf{x} \ge 0 \text{ for every } \mathbf{x} \end{gathered}

Negative definite and negative semidefinite are the same with <0< 0 and ≤0\le 0. A matrix whose form takes both signs is indefinite.

Every positive definite matrix is also positive semidefinite. When this module calls a matrix semidefinite, it means that qq is also 0 at some x≠0\mathbf{x} \neq \mathbf{0}, as for JJ.

So AA looks positive definite, JJ positive semidefinite, NN indefinite and −S-S negative definite. A table can only rule things out: one negative value proves that NN is not semidefinite. No finite table proves that AA is positive everywhere; the next two sections give tests that do.

One quick check comes free. q(ei)=aiiq(\mathbf{e}_i) = a_{ii}, the ii-th diagonal entry, so a positive definite matrix has every diagonal entry positive. That is needed but not enough: NN has 1 and 1 on its diagonal and is indefinite.

Try it

The loop prints each row of the table: qq at the five points, for each of the four matrices.

int(…) prints whole numbers; each value is already a whole number.

⌘/Ctrl + Enter runs the cell

The eigenvalue test

Lesson 3.6.3 showed that a symmetric matrix has real eigenvalues λ1,…,λn\lambda_1, \ldots, \lambda_n and perpendicular unit eigenvectors q1,…,qn\mathbf{q}_1, \ldots, \mathbf{q}_n, with A=QΛQ⊤A = Q\Lambda Q^\top. Here QQ has the eigenvectors as its columns and Λ\Lambda is the diagonal matrix of eigenvalues.

Measure x\mathbf{x} along the eigenvectors instead of the axes: yi=qi⋅xy_i = \mathbf{q}_i \cdot \mathbf{x}, or y=Q⊤x\mathbf{y} = Q^\top\mathbf{x}. Then x⊤Ax=x⊤QΛQ⊤x=y⊤Λy\mathbf{x}^\top A\mathbf{x} = \mathbf{x}^\top Q\Lambda Q^\top\mathbf{x} = \mathbf{y}^\top\Lambda\mathbf{y}, and the cross terms disappear:

x⊤A x=λ1y12+⋯+λnyn2\mathbf{x}^\top A\,\mathbf{x} = \lambda_1 y_1^2 + \cdots + \lambda_n y_n^2

Take S=(2112)S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}. Its eigenvalues are 3, along q1=12(1,1)\mathbf{q}_1 = \frac{1}{\sqrt{2}}(1, 1), and 1, along q2=12(1,−1)\mathbf{q}_2 = \frac{1}{\sqrt{2}}(1, -1). So y1=x1+x22y_1 = \frac{x_1 + x_2}{\sqrt{2}}, y2=x1−x22y_2 = \frac{x_1 - x_2}{\sqrt{2}}, and

q(x)=2x12+2x1x2+2x22=3y12+y22=1.5(x1+x2)2+0.5(x1−x2)2\begin{aligned} q(\mathbf{x}) &= 2x_1^2 + 2x_1x_2 + 2x_2^2 \\ &= 3y_1^2 + y_2^2 \\ &= 1.5(x_1 + x_2)^2 \\ &\quad + 0.5(x_1 - x_2)^2 \end{aligned}

Expand the right side to check: 1.5+0.5=21.5 + 0.5 = 2 for each square, and 3−1=23 - 1 = 2 for the cross term. At (2,−1)(2, -1) both sides give 6.

A sum λ1y12+⋯+λnyn2\lambda_1y_1^2 + \cdots + \lambda_ny_n^2 is positive for every y≠0\mathbf{y} \neq \mathbf{0} exactly when every λi>0\lambda_i > 0. And y=0\mathbf{y} = \mathbf{0} only when x=0\mathbf{x} = \mathbf{0}, because QQ only turns or reflects the plane.

Rule: The eigenvalue test

every λi>0  ⟺  positive definiteevery λi≥0  ⟺  positive semidefinite\begin{gathered} \text{every } \lambda_i > 0 \\ \iff \text{positive definite} \\[6pt] \text{every } \lambda_i \ge 0 \\ \iff \text{positive semidefinite} \end{gathered}

All λi<0\lambda_i < 0 means negative definite. Eigenvalues of both signs mean indefinite: qq is positive along an eigenvector with λi>0\lambda_i > 0 and negative along one with λi<0\lambda_i < 0.

matrixeigenvalueskind
AA1.382, 3.618positive definite
JJ0, 2positive semidefinite
NN−1-1, 3indefinite
−S-S−3-3, −1-1negative definite

The eigenvectors show where the signs are. NN has λ=−1\lambda = -1 along 12(1,−1)\frac{1}{\sqrt{2}}(1, -1), and there q=−1q = -1. JJ has λ=0\lambda = 0 along (1,−1)(1, -1), the line where (x1+x2)2=0(x_1 + x_2)^2 = 0.

For a unit vector, y12+⋯+yn2=1y_1^2 + \cdots + y_n^2 = 1, so qq is an average of the eigenvalues with weights yi2y_i^2. It therefore runs from the smallest eigenvalue to the largest: from 1 to 3 for SS, from −1-1 to 3 for NN.

For 2×22 \times 2 matrices lesson 3.6.1 gives a shortcut: λ1λ2=det⁡A\lambda_1\lambda_2 = \det A and λ1+λ2\lambda_1 + \lambda_2 is the trace, the sum of the diagonal. det⁡A>0\det A > 0 means the two eigenvalues have the same sign, and the trace says which. det⁡N=−3<0\det N = -3 < 0 means opposite signs: indefinite.

Try it

np.linalg.eigh (lesson 3.6.3) returns the eigenvalues, smallest first, and the eigenvectors as columns. The second line makes each eigenvector's first entry positive, since their signs are arbitrary.

The loop compares q(x)q(\mathbf{x}) with ∑λiyi2\sum \lambda_i y_i^2 and with 1.5(x1+x2)2+0.5(x1−x2)21.5(x_1 + x_2)^2 + 0.5(x_1 - x_2)^2.

⌘/Ctrl + Enter runs the cell

Testing on a computer

np.linalg.eigvalsh returns just the eigenvalues of a symmetric matrix, smallest first: it is eigh without the eigenvectors. Testing "every λ≥0\lambda \ge 0" needs care. A zero eigenvalue often comes out as a tiny number such as 10−1610^{-16}, positive or negative depending on the computer.

So compare with a small tolerance, scaled to the size of the matrix, as lesson 3.4.1 did for determinants. classify below treats any eigenvalue within 10−1010^{-10} times the largest one as zero.

Try it

classify applies the eigenvalue test with that tolerance. Each line prints the eigenvalues, the trace, the determinant and the verdict.

Adding 0.0 turns a -0. into 0.. The last line evaluates NN's form at the unit vector 12(1,−1)\frac{1}{\sqrt{2}}(1, -1): the eigenvalue −1-1.

⌘/Ctrl + Enter runs the cell

The test by leading minors

Eigenvalues are hard to find by hand beyond 2×22 \times 2. Determinants give a test you can do on paper.

The leading minors of AA are the determinants of its top-left corners (lesson 3.4.1). They run from the 1×11 \times 1 corner a11a_{11}, through the 2×22 \times 2 corner, up to det⁡A\det A itself.

Rule: The leading-minor test

2×2: a>0 and ac−b2>0every leading minor>0\begin{gathered} 2 \times 2:\ a > 0 \text{ and } ac - b^2 > 0 \\[4pt] \text{every leading minor} > 0 \end{gathered}

A symmetric matrix is positive definite exactly when all its leading minors are positive. It is negative definite exactly when they alternate in sign, starting negative: −,+,−,…-, +, -, \ldots

Why it works for 2×22 \times 2: complete the square. For a≠0a \neq 0,

ax12+2bx1x2+cx22=a(x1+bax2)2+ac−b2a x22\begin{aligned} & ax_1^2 + 2bx_1x_2 + cx_2^2 \\ &= a\Big(x_1 + \frac{b}{a}x_2\Big)^2 \\ &\quad + \frac{ac - b^2}{a}\,x_2^2 \end{aligned}

If a>0a > 0 and ac−b2>0ac - b^2 > 0, both coefficients are positive. The sum of the two squares is then 0 only if x2=0x_2 = 0 and then x1=0x_1 = 0.

For AA: 3(x1+13x2)2+53x223\big(x_1 + \frac{1}{3}x_2\big)^2 + \frac{5}{3}x_2^2, which at (1,−1)(1, -1) is 43+53=3\frac{4}{3} + \frac{5}{3} = 3, as in the table. Lesson 3.7.2 turns this completed square into a factorisation of AA.

Two 3×33 \times 3 examples. Lesson 3.2.3's

K=(4−10−132025)K = \begin{pmatrix} 4 & -1 & 0 \\ -1 & 3 & 2 \\ 0 & 2 & 5 \end{pmatrix}

has leading minors 4, 4⋅3−(−1)(−1)=114 \cdot 3 - (-1)(-1) = 11 and det⁡K=39\det K = 39, all positive: positive definite.

T=(212121211)T = \begin{pmatrix} 2 & 1 & 2 \\ 1 & 2 & 1 \\ 2 & 1 & 1 \end{pmatrix}

passes the first two, 2 and 3, but det⁡T=−3\det T = -3. So TT is not positive definite, and indeed q(1,0,−1)=2−4+1=−1q(1, 0, -1) = 2 - 4 + 1 = -1. Its eigenvalues are −0.5758-0.5758, 1.1873 and 4.3885: indefinite.

Where the test breaks: semidefinite matrices. Leading minors that are ≥0\ge 0 do not prove semidefinite. E=(000−1)E = \begin{pmatrix} 0 & 0 \\ 0 & -1 \end{pmatrix} has leading minors 0 and 0, yet q(x)=−x22q(\mathbf{x}) = -x_2^2, which is negative at (0,1)(0, 1). For semidefinite questions, use the eigenvalues.

Try it

leading_minors takes the determinant of each top-left corner, M[:k, :k]. Each line prints the minors, then the eigenvalues.

Then q(1,0,−1)q(1, 0, -1) for TT, and the completed square for AA at (1,−1)(1, -1).

⌘/Ctrl + Enter runs the cell

Level curves: ellipses and hyperbolas

A level curve of qq is the set of points where q(x)q(\mathbf{x}) takes one fixed value, like a contour line on a map. Module 4.1 draws them for any function of two variables; for a quadratic form, the eigenvalues decide their shape.

Along the eigenvector qi\mathbf{q}_i, q=λiyi2q = \lambda_i y_i^2, so q=1q = 1 where yi=1/λiy_i = 1/\sqrt{\lambda_i}. A large eigenvalue makes qq climb fast, so the curve is close to the origin in that direction.

Level curves of SS, JJ and NN. Positive definite gives ellipses, here with semi-axes 1/3≈0.581/\sqrt{3} \approx 0.58 and 1 for q=1q = 1. A zero eigenvalue gives parallel lines, and eigenvalues of both signs give hyperbolas, with q<0q < 0 in the shaded sectors.

  • Positive definite: each level curve q=k>0q = k > 0 is an ellipse, with its axes along the eigenvectors and semi-axes k/λi\sqrt{k/\lambda_i}. Seen as a height over the plane, qq is a bowl with its bottom at the origin.
  • Semidefinite, one zero eigenvalue: qq does not grow along that eigenvector, so the curves are parallel lines. The surface is a trough.
  • Indefinite: the curves are hyperbolas. NN has the same eigenvectors as SS, and q=3y12−y22q = 3y_1^2 - y_2^2. It is 0 on the two lines y2=±3 y1y_2 = \pm\sqrt{3}\,y_1, which separate the positive part from the negative part. The surface is a saddle.

Rule: Level curves of a quadratic form

q=1 meets the axis of qiat distance 1/λi if λi>0\begin{gathered} q = 1 \text{ meets the axis of } \mathbf{q}_i \\[4pt] \text{at distance } 1/\sqrt{\lambda_i} \text{ if } \lambda_i > 0 \end{gathered}

All λi>0\lambda_i > 0: ellipses. One λi=0\lambda_i = 0, the other positive: parallel lines. Eigenvalues of both signs: hyperbolas.

Try it

The first loop checks four points of SS's ellipses. They are the ends of the axes of q=1q = 1, at distances 1/31/\sqrt{3} and 1, then of q=4q = 4, twice as far.

For NN, 13q1\frac{1}{\sqrt{3}}\mathbf{q}_1 is on q=1q = 1 and q2\mathbf{q}_2 on q=−1q = -1; q1+3 q2\mathbf{q}_1 + \sqrt{3}\,\mathbf{q}_2 is on a line where q=0q = 0.

⌘/Ctrl + Enter runs the cell

Matrices that are always semidefinite

For any m×nm \times n matrix MM, lesson 3.2.3 showed that M⊤MM^\top M is symmetric. Its form is a squared length:

x⊤M⊤M x=(Mx)⊤(Mx)=∥Mx∥2≥0\begin{aligned} \mathbf{x}^\top M^\top M\,\mathbf{x} &= (M\mathbf{x})^\top(M\mathbf{x}) \\ &= \lVert M\mathbf{x} \rVert^2 \ge 0 \end{aligned}

So M⊤MM^\top M is always positive semidefinite. It is positive definite exactly when Mx=0M\mathbf{x} = \mathbf{0} only for x=0\mathbf{x} = \mathbf{0}: when the columns of MM are independent, with rank nn (lesson 3.3.2).

Lesson 3.2.3's M=(1203−14)M = \begin{pmatrix} 1 & 2 & 0 \\ 3 & -1 & 4 \end{pmatrix} is 2×32 \times 3, so its rank is at most 2 and M⊤MM^\top M is only semidefinite:

M⊤M=(10−112−15−412−416)M^\top M = \begin{pmatrix} 10 & -1 & 12 \\ -1 & 5 & -4 \\ 12 & -4 & 16 \end{pmatrix}

At x=(1,1,−1)\mathbf{x} = (1, 1, -1), Mx=(3,−2)M\mathbf{x} = (3, -2) and the form is 9+4=139 + 4 = 13. At x=(−8,4,7)\mathbf{x} = (-8, 4, 7), Mx=0M\mathbf{x} = \mathbf{0} and the form is 0. The eigenvalues are 0, 4.9525 and 26.0475; the smaller matrix MM⊤MM^\top has eigenvalues 4.9525 and 26.0475, both positive.

Covariance matrices. In case study 3.2.5, w⊤Σw\mathbf{w}^\top\Sigma\mathbf{w} is the variance of a portfolio, and a variance is never negative. So a covariance matrix must be positive semidefinite.

A sample covariance matrix is built as M⊤MM^\top M divided by n−1n - 1, from the centred returns, so it always is. The three assets' Σ\Sigma has eigenvalues 0.011741, 0.022502 and 0.075058: positive definite. Case study 3.7.4 uses these tests to catch correlation matrices that cannot be real.

Try it

M⊤MM^\top M and its form at two points; at (−8,4,7)(-8, 4, 7), Mx=0M\mathbf{x} = \mathbf{0}.

The smallest eigenvalue of M⊤MM^\top M is 0, which prints as a tiny number unless rounded; the check lam.min() >= -1e-12 allows for that. matrix_rank gives 2. Last come MM⊤MM^\top and the three assets' Σ\Sigma.

⌘/Ctrl + Enter runs the cell

Lesson 4.3.2 applies the same tests to the matrix of second derivatives of a function, to tell a minimum from a maximum or a saddle.

Common mistakes

  1. The cross term is 2b2b. In 3x12+4x1x2+2x223x_1^2 + 4x_1x_2 + 2x_2^2 the off-diagonal entry is 2, not 4: A=(3222)A = \begin{pmatrix} 3 & 2 \\ 2 & 2 \end{pmatrix}.
  2. Positive entries do not make a matrix positive definite. N=(1221)N = \begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} is indefinite; (2−1−12)\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}, with negative entries, is positive definite (eigenvalues 1 and 3).
  3. A positive diagonal is needed, not enough. It rules out matrices with a diagonal entry ≤0\le 0, nothing more.
  4. A positive determinant is not enough. −S-S has det⁡=3\det = 3 and is negative definite. Check every leading minor, or the trace too for 2×22 \times 2.
  5. Leading minors ≥0\ge 0 do not prove semidefinite. E=(000−1)E = \begin{pmatrix} 0 & 0 \\ 0 & -1 \end{pmatrix} passes and is not. Use the eigenvalues.
  6. Use the symmetric matrix. B=(1401)B = \begin{pmatrix} 1 & 4 \\ 0 & 1 \end{pmatrix} has eigenvalues 1 and 1, yet its form x12+4x1x2+x22x_1^2 + 4x_1x_2 + x_2^2 is −2-2 at (1,−1)(1, -1). Test 12(B+B⊤)\frac{1}{2}(B + B^\top), whose eigenvalues are −1-1 and 3.
  7. Allow for rounding. A zero eigenvalue prints as a tiny number of either sign. Compare with a tolerance, never with exactly 0.

Quadratic forms and positive definiteness

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A quadratic form is q(x)=x⊤Ax=∑i∑jaijxixjq(\mathbf{x}) = \mathbf{x}^\top A\mathbf{x} = \sum_i\sum_j a_{ij}x_ix_j, with AA symmetric; for 2×22 \times 2, ax12+2bx1x2+cx22ax_1^2 + 2bx_1x_2 + cx_2^2. q(cx)=c2q(x)q(c\mathbf{x}) = c^2q(\mathbf{x}).
  • Positive definite: q>0q > 0 for every x≠0\mathbf{x} \neq \mathbf{0}. Positive semidefinite: q≥0q \ge 0. Indefinite: both signs. Negative (semi)definite: the reverse.
  • Eigenvalue test: q=λ1y12+⋯+λnyn2q = \lambda_1y_1^2 + \cdots + \lambda_ny_n^2 along the eigenvectors, so all λi>0\lambda_i > 0 means positive definite and all λi≥0\lambda_i \ge 0 semidefinite. On unit vectors qq runs from λmin⁡\lambda_{\min} to λmax⁡\lambda_{\max}.
  • Leading-minor test: positive definite exactly when every top-left determinant is positive (a>0a > 0, ac−b2>0ac - b^2 > 0 for 2×22 \times 2). It does not test semidefinite.
  • Level curves: ellipses with semi-axes 1/λi1/\sqrt{\lambda_i} for q=1q = 1 (definite), parallel lines (one zero eigenvalue), hyperbolas (indefinite).
  • M⊤MM^\top M is always positive semidefinite, since its form is ∥Mx∥2\lVert M\mathbf{x} \rVert^2; so is every covariance matrix. In code, use eigvalsh with a tolerance.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.