Skip to content
Glacius
Linear algebraConcept reference

Diagonal matrices

A square diagonal matrix has zero entries off its main diagonal and multiplies each coordinate by its matching diagonal entry.

On this page 7 sections
  1. Overview
  2. A square diagonal matrix has zeros off its main diagonal
  3. D=operatornamediag(2,3) sends (1,1) to (2,3)
  4. Check your understanding
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

01A square diagonal matrix has zeros off its main diagonal#

A square diagonal matrix has zeros off its main diagonal. Each diagonal entry scales one input coordinate.

D has diagonal entries 2 and −1. Input x=(3,−2) becomes Dx=(6,2): horizontal coordinate doubles and vertical coordinate reverses sign. Equal coordinate units let the arrows show this transformation.D has diagonal entries 2 and −1. Input x=(3,−2) becomes Dx=(6,2): horizontal coordinate doubles and vertical coordinate reverses sign. Equal coordinate units let the arrows show this transformation.
Figure 1The two coordinates use separate multipliers.
Link to this figure ↗Download SVGDownload PNG

For D=diag(2,1)D=\operatorname{diag}(2,-1) and x=(3,2)x=(3,-2), the first output is 2(3)=62(3)=6. The second is (1)(2)=2(-1)(-2)=2.

The output column vector is

Dx=(6,2)Dx=(6,2)

Here and throughout this lesson, tuples list column-vector coordinates.

For D=diag(d1,d2)D=\operatorname{diag}(d_1,d_2), each factor stays with its own coordinate.

Coordinate by coordinate,

Dx=(d1x1,d2x2)Dx=(d_1x_1,d_2x_2)

A zero factor erases that coordinate. A negative factor reverses its sign.

Check your reasoning

D=diag(3,2)D=\operatorname{diag}(3,-2) and x=(1,4)x=(-1,4). What is the second coordinate of DxDx?

Show answer and explanation
-8

The second factor is 2-2: (2)(4)=8(-2)(4)=-8.

02D=operatornamediag(2,3) sends (1,1) to (2,3)#

D=diag(2,3)D=\operatorname{diag}(2,3) sends (1,1)(1,1) to (2,3)(2,3). The first coordinate doubles; the second triples.

The equal factors in diag(2,2)\operatorname{diag}(2,2) would instead double both coordinates. A diagonal matrix need not use one common multiplier.

Check your reasoning

A filter doubles channel 1 and silences channel 2. Choose its diagonal matrix.

  1. Adiag(0,2)\operatorname{diag}(0,2)
  2. Bdiag(2,0)\operatorname{diag}(2,0)
  3. Cdiag(2,1)\operatorname{diag}(2,1)
Show answer and explanation
diag(2,0)\operatorname{diag}(2,0)

Use factors 2 and 0, in that order.

03Check your understanding#

Check your reasoning

D=diag(1,3)D=\operatorname{diag}(-1,3) sends (2,1)(2,1) to (2,1)(-2,1), a learner says. What needs fixing?

  1. AFirst entry must be 2.
  2. BBoth entries are correct.
  3. CSecond entry must be 3.
Show answer and explanation
Second entry must be 3.

The second entry also scales: 3(1)=33(1)=3.

Key takeaway

Match each coordinate with its diagonal multiplier.

  • Apply each diagonal entry to its matching coordinate.

Sources & further reading

  1. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Diagonal matrices.” Math behind ML. /learn/la-diagonal