# Diagonal matrix

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Diagonal_matrix
> Markdown URL: https://mediated.wiki/source/Diagonal_matrix.md
> Source: https://en.wikipedia.org/wiki/Diagonal_matrix
> Source revision: 1348257885
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Matrix whose only nonzero elements are on its main diagonal

This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (June 2025) (Learn how and when to remove this message)

In [linear algebra](/source/Linear_algebra), a **diagonal matrix** is a [matrix](/source/Matrix_(mathematics)) in which the entries outside the [main diagonal](/source/Main_diagonal) are all zero; the term usually refers to [square matrices](/source/Square_matrices). Elements of the main diagonal can either be zero or nonzero. An example of a 2×2 diagonal matrix is [ 3 0 0 2 ] {\displaystyle \left[{\begin{smallmatrix}3&0\\0&2\end{smallmatrix}}\right]} , while an example of a 3×3 diagonal matrix is [ 6 0 0 0 5 0 0 0 4 ] {\displaystyle \left[{\begin{smallmatrix}6&0&0\\0&5&0\\0&0&4\end{smallmatrix}}\right]} . An [identity matrix](/source/Identity_matrix) of any size, or any multiple of it is a diagonal matrix called a [*scalar matrix*](#Scalar_matrix), for example, [ 0.5 0 0 0.5 ] {\displaystyle \left[{\begin{smallmatrix}0.5&0\\0&0.5\end{smallmatrix}}\right]} . In [geometry](/source/Geometry), a diagonal matrix may be used as a *[scaling matrix](/source/Scaling_matrix)*, since matrix multiplication with it results in changing scale (size) and possibly also [shape](/source/Shape); only a scalar matrix results in uniform change in scale.

## Definition

As stated above, a diagonal matrix is a matrix in which all off-diagonal entries are zero. That is, the matrix **D** = (*d**i*,*j*) with n columns and n rows is diagonal if ∀ i , j ∈ { 1 , 2 , … , n } , i ≠ j ⟹ d i , j = 0. {\displaystyle \forall i,j\in \{1,2,\ldots ,n\},i\neq j\implies d_{i,j}=0.}

However, the main diagonal entries are unrestricted.

The term *diagonal matrix* may sometimes refer to a **rectangular diagonal matrix**, which is an m-by-n matrix with all the entries not of the form *d**i*,*i* being zero. For example: [ 1 0 0 0 4 0 0 0 − 3 0 0 0 ] or [ 1 0 0 0 0 0 4 0 0 0 0 0 − 3 0 0 ] {\displaystyle {\begin{bmatrix}1&0&0\\0&4&0\\0&0&-3\\0&0&0\\\end{bmatrix}}\quad {\text{or}}\quad {\begin{bmatrix}1&0&0&0&0\\0&4&0&0&0\\0&0&-3&0&0\end{bmatrix}}}

More often, however, *diagonal matrix* refers to square matrices, which can be specified explicitly as a **square diagonal matrix**. A square diagonal matrix is a [symmetric matrix](/source/Symmetric_matrix), so this can also be called a **symmetric diagonal matrix**.

The following matrix is square diagonal matrix: [ 1 0 0 0 4 0 0 0 − 2 ] {\displaystyle {\begin{bmatrix}1&0&0\\0&4&0\\0&0&-2\end{bmatrix}}}

If the entries are [real numbers](/source/Real_numbers) or [complex numbers](/source/Complex_numbers), then it is a [normal matrix](/source/Normal_matrix) as well.

In the remainder of this article we will consider only square diagonal matrices, and refer to them simply as "diagonal matrices".

## Vector-to-matrix diag operator

A diagonal matrix **D** can be constructed from a vector a = [ a 1 … a n ] T {\displaystyle \mathbf {a} ={\begin{bmatrix}a_{1}&\dots &a_{n}\end{bmatrix}}^{\textsf {T}}} using the diag {\displaystyle \operatorname {diag} } operator: D = diag ⁡ ( a 1 , … , a n ) . {\displaystyle \mathbf {D} =\operatorname {diag} (a_{1},\dots ,a_{n}).}

This may be written more compactly as D = diag ⁡ ( a ) {\displaystyle \mathbf {D} =\operatorname {diag} (\mathbf {a} )} .

The same operator is also used to represent [block diagonal matrices](/source/Block_matrix#Block_diagonal_matrices) as A = diag ⁡ ( A 1 , … , A n ) {\displaystyle \mathbf {A} =\operatorname {diag} (\mathbf {A} _{1},\dots ,\mathbf {A} _{n})} where each argument **A***i* is a matrix.

The diag operator may be written as diag ⁡ ( a ) = ( a 1 T ) ∘ I , {\displaystyle \operatorname {diag} (\mathbf {a} )=\left(\mathbf {a} \mathbf {1} ^{\textsf {T}}\right)\circ \mathbf {I} ,} where ∘ {\displaystyle \circ } represents the [Hadamard product](/source/Hadamard_product_(matrices)), and **1** is a constant vector with elements 1.

## Matrix-to-vector diag operator

The inverse matrix-to-vector diag operator is sometimes denoted by the identically named diag ⁡ ( D ) = [ a 1 … a n ] T , {\displaystyle \operatorname {diag} (\mathbf {D} )={\begin{bmatrix}a_{1}&\dots &a_{n}\end{bmatrix}}^{\textsf {T}},} where the argument is now a matrix, and the result is a vector of its diagonal entries.

The following property holds: diag ⁡ ( A B ) = ∑ j ( A ∘ B T ) i j = ( A ∘ B T ) 1 . {\displaystyle \operatorname {diag} (\mathbf {A} \mathbf {B} )=\sum _{j}\left(\mathbf {A} \circ \mathbf {B} ^{\textsf {T}}\right)_{ij}=\left(\mathbf {A} \circ \mathbf {B} ^{\textsf {T}}\right)\mathbf {1} .}

## Scalar matrix

A diagonal matrix with equal diagonal entries is a **scalar matrix**; that is, a scalar multiple λ of the [identity matrix](/source/Identity_matrix) **I**. Its effect on a [vector](/source/Vector_(mathematics_and_physics)) is [scalar multiplication](/source/Scalar_multiplication) by λ. For example, a 3×3 scalar matrix has the form: [ λ 0 0 0 λ 0 0 0 λ ] ≡ λ I 3 {\displaystyle {\begin{bmatrix}\lambda &0&0\\0&\lambda &0\\0&0&\lambda \end{bmatrix}}\equiv \lambda {\boldsymbol {I}}_{3}}

The scalar matrices are the [center](/source/Center_of_an_algebra) of the algebra of matrices: that is, they are precisely the matrices that [commute](/source/Commute_(mathematics)) with all other square matrices of the same size.[a] By contrast, over a [field](/source/Field_(mathematics)) (like the real numbers), a diagonal matrix with all diagonal elements distinct only commutes with diagonal matrices (its [centralizer](/source/Centralizer) is the set of diagonal matrices). That is because if a diagonal matrix D = diag ⁡ ( a 1 , … , a n ) {\displaystyle \mathbf {D} =\operatorname {diag} (a_{1},\dots ,a_{n})} has a i ≠ a j , {\displaystyle a_{i}\neq a_{j},} then given a matrix **M** with m i j ≠ 0 , {\displaystyle m_{ij}\neq 0,} the (*i*, *j*) term of the products are: ( D M ) i j = a i m i j {\displaystyle (\mathbf {DM} )_{ij}=a_{i}m_{ij}} and ( M D ) i j = m i j a j , {\displaystyle (\mathbf {MD} )_{ij}=m_{ij}a_{j},} and a j m i j ≠ m i j a i {\displaystyle a_{j}m_{ij}\neq m_{ij}a_{i}} (since one can divide by mij), so they do not commute unless the off-diagonal terms are zero.[b] Diagonal matrices where the diagonal entries are not all equal or all distinct have centralizers intermediate between the whole space and only diagonal matrices.[1]

For an abstract vector space V (rather than the concrete vector space Kn), the analog of scalar matrices are **scalar transformations**. This is true more generally for a [module](/source/Module_(ring_theory)) M over a [ring](/source/Ring_(algebra)) R, with the [endomorphism algebra](/source/Endomorphism_algebra) End(*M*) (algebra of linear operators on M) replacing the algebra of matrices. Formally, scalar multiplication is a linear map, inducing a map R → End ⁡ ( M ) , {\displaystyle R\to \operatorname {End} (M),} (from a scalar λ to its corresponding scalar transformation, multiplication by λ) exhibiting End(*M*) as a R-[algebra](/source/Algebra_(ring_theory)). For vector spaces, the scalar transforms are exactly the [center](/source/Center_of_a_ring) of the endomorphism algebra, and, similarly, scalar invertible transforms are the center of the [general linear group](/source/General_linear_group) GL(*V*). The former is more generally true [free modules](/source/Free_module) M ≅ R n , {\displaystyle M\cong R^{n},} for which the endomorphism algebra is isomorphic to a matrix algebra.

## Vector operations

Multiplying a vector by a diagonal matrix multiplies each of the terms by the corresponding diagonal entry. Given a diagonal matrix D = diag ⁡ ( a 1 , … , a n ) {\displaystyle \mathbf {D} =\operatorname {diag} (a_{1},\dots ,a_{n})} and a vector v = [ x 1 ⋯ x n ] T {\displaystyle \mathbf {v} ={\begin{bmatrix}x_{1}&\dotsm &x_{n}\end{bmatrix}}^{\textsf {T}}} , the product is: D v = diag ⁡ ( a 1 , … , a n ) [ x 1 ⋮ x n ] = [ a 1 ⋱ a n ] [ x 1 ⋮ x n ] = [ a 1 x 1 ⋮ a n x n ] . {\displaystyle \mathbf {D} \mathbf {v} =\operatorname {diag} (a_{1},\dots ,a_{n}){\begin{bmatrix}x_{1}\\\vdots \\x_{n}\end{bmatrix}}={\begin{bmatrix}a_{1}\\&\ddots \\&&a_{n}\end{bmatrix}}{\begin{bmatrix}x_{1}\\\vdots \\x_{n}\end{bmatrix}}={\begin{bmatrix}a_{1}x_{1}\\\vdots \\a_{n}x_{n}\end{bmatrix}}.}

This can be expressed more compactly by using a vector instead of a diagonal matrix, d = [ a 1 ⋯ a n ] T {\displaystyle \mathbf {d} ={\begin{bmatrix}a_{1}&\dotsm &a_{n}\end{bmatrix}}^{\textsf {T}}} , and taking the [Hadamard product](/source/Hadamard_product_(matrices)) of the vectors (entrywise product), denoted d ∘ v {\displaystyle \mathbf {d} \circ \mathbf {v} } :

D v = d ∘ v = [ a 1 ⋮ a n ] ∘ [ x 1 ⋮ x n ] = [ a 1 x 1 ⋮ a n x n ] . {\displaystyle \mathbf {D} \mathbf {v} =\mathbf {d} \circ \mathbf {v} ={\begin{bmatrix}a_{1}\\\vdots \\a_{n}\end{bmatrix}}\circ {\begin{bmatrix}x_{1}\\\vdots \\x_{n}\end{bmatrix}}={\begin{bmatrix}a_{1}x_{1}\\\vdots \\a_{n}x_{n}\end{bmatrix}}.}

This is mathematically equivalent, but avoids storing all the zero terms of this [sparse matrix](/source/Sparse_matrix). This product is thus used in [machine learning](/source/Machine_learning), such as computing products of derivatives in [backpropagation](/source/Backpropagation) or multiplying IDF weights in [TF-IDF](/source/TF-IDF),[2] since some [BLAS](/source/BLAS) frameworks, which multiply matrices efficiently, do not include Hadamard product capability directly.[3]

## Matrix operations

The operations of matrix addition and [matrix multiplication](/source/Matrix_multiplication) are especially simple for diagonal matrices. Write diag(*a*1, ..., *an*) for a diagonal matrix whose diagonal entries starting in the upper left corner are *a*1, ..., *an*. Then, for [addition](/source/Matrix_addition), we have

diag ⁡ ( a 1 , … , a n ) + diag ⁡ ( b 1 , … , b n ) = diag ⁡ ( a 1 + b 1 , … , a n + b n ) {\displaystyle \operatorname {diag} (a_{1},\,\ldots ,\,a_{n})+\operatorname {diag} (b_{1},\,\ldots ,\,b_{n})=\operatorname {diag} (a_{1}+b_{1},\,\ldots ,\,a_{n}+b_{n})}

and for [matrix multiplication](/source/Matrix_multiplication),

diag ⁡ ( a 1 , … , a n ) diag ⁡ ( b 1 , … , b n ) = diag ⁡ ( a 1 b 1 , … , a n b n ) . {\displaystyle \operatorname {diag} (a_{1},\,\ldots ,\,a_{n})\operatorname {diag} (b_{1},\,\ldots ,\,b_{n})=\operatorname {diag} (a_{1}b_{1},\,\ldots ,\,a_{n}b_{n}).}

The diagonal matrix diag(*a*1, ..., *an*) is [invertible](/source/Invertible_matrix) [if and only if](/source/If_and_only_if) the entries *a*1, ..., *an* are all nonzero. In this case, we have

diag ⁡ ( a 1 , … , a n ) − 1 = diag ⁡ ( a 1 − 1 , … , a n − 1 ) . {\displaystyle \operatorname {diag} (a_{1},\,\ldots ,\,a_{n})^{-1}=\operatorname {diag} (a_{1}^{-1},\,\ldots ,\,a_{n}^{-1}).}

In particular, the diagonal matrices form a [subring](/source/Subring) of the ring of all n-by-n matrices.

Multiplying an n-by-n matrix **A** from the *left* with diag(*a*1, ..., *an*) amounts to multiplying the i-th *row* of **A** by ai for all i; multiplying the matrix **A** from the *right* with diag(*a*1, ..., *an*) amounts to multiplying the i-th *column* of **A** by ai for all i.

## Operator matrix in eigenbasis

Main articles: [Transformation matrix § Finding the matrix of a transformation](/source/Transformation_matrix#Finding_the_matrix_of_a_transformation), and [Eigenvalues and eigenvectors](/source/Eigenvalues_and_eigenvectors)

As explained in [determining coefficients of operator matrix](/source/Transformation_matrix#Finding_the_matrix_of_a_transformation), there is a special basis, **e**1, ..., **e***n*, for which the matrix **A** takes the diagonal form. Hence, in the defining equation A e j = ∑ i a i , j e i {\textstyle \mathbf {Ae} _{j}=\sum _{i}a_{i,j}\mathbf {e} _{i}} , all coefficients ai, j with *i* ≠ *j* are zero, leaving only one term per sum. The surviving diagonal elements, ai, j, are known as **eigenvalues** and designated with λi in the equation, which reduces to A e i = λ i e i . {\displaystyle \mathbf {Ae} _{i}=\lambda _{i}\mathbf {e} _{i}.} The resulting equation is known as **eigenvalue equation**[4] and used to derive the [characteristic polynomial](/source/Characteristic_polynomial) and, further, [eigenvalues and eigenvectors](/source/Eigenvalues_and_eigenvectors).

In other words, the [eigenvalues](/source/Eigenvalue) of diag(*λ*1, ..., *λ**n*) are *λ*1, ..., *λ**n* with associated [eigenvectors](/source/Eigenvectors) of **e**1, ..., **e***n*.

## Properties

- The [determinant](/source/Determinant) of diag(*a*1, ..., *a**n*) is the product *a*1⋯*a**n*.

- The [adjugate](/source/Adjugate) of a diagonal matrix is again diagonal.

- Where all matrices are square, - A matrix is diagonal if and only if it is triangular and [normal](/source/Normal_matrix). - A matrix is diagonal if and only if it is both [upper-](/source/Triangular_matrix) and [lower-triangular](/source/Triangular_matrix). - A diagonal matrix is [symmetric](/source/Symmetric_matrix).

- The [identity matrix](/source/Identity_matrix) **I***n* and [zero matrix](/source/Zero_matrix) are diagonal.

- A 1×1 matrix is always diagonal.

- The square of a 2×2 matrix with zero [trace](/source/Trace_(linear_algebra)) is always diagonal.

- The inverse of a diagonal matrix is obtained by taking the reciprocals of the elements on the diagonal

## Applications

Diagonal matrices occur in many areas of linear algebra. Because of the simple description of the matrix operation and eigenvalues/eigenvectors given above, it is typically desirable to represent a given matrix or [linear map](/source/Linear_operator) by a diagonal matrix.

In fact, a given n-by-n matrix **A** is [similar](/source/Similar_matrix) to a diagonal matrix (meaning that there is a matrix **X** such that **X**−1**AX** is diagonal) if and only if it has n [linearly independent](/source/Linearly_independent) eigenvectors. Such matrices are said to be [diagonalizable](/source/Diagonalizable_matrix).

Over the [field](/source/Field_(mathematics)) of [real](/source/Real_number) or [complex](/source/Complex_number) numbers, more is true. The [spectral theorem](/source/Spectral_theorem) says that every [normal matrix](/source/Normal_matrix) is [unitarily similar](/source/Matrix_similarity) to a diagonal matrix (if **AA**∗ = **A**∗**A** then there exists a [unitary matrix](/source/Unitary_matrix) **U** such that **UAU**∗ is diagonal). Furthermore, the [singular value decomposition](/source/Singular_value_decomposition) implies that for any matrix **A**, there exist unitary matrices **U** and **V** such that **U**∗**AV** is diagonal with positive entries.

## Operator theory

In [operator theory](/source/Operator_theory), particularly the study of [PDEs](/source/PDEs), operators are particularly easy to understand and PDEs easy to solve if the operator is diagonal with respect to the basis with which one is working; this corresponds to a [separable partial differential equation](/source/Separable_partial_differential_equation). Therefore, a key technique to understanding operators is a change of coordinates—in the language of operators, an [integral transform](/source/Integral_transform)—which changes the basis to an [eigenbasis](/source/Eigenbasis) of [eigenfunctions](/source/Eigenfunction): which makes the equation separable. An important example of this is the [Fourier transform](/source/Fourier_transform), which diagonalizes constant coefficient differentiation operators (or more generally translation invariant operators), such as the Laplacian operator, say, in the [heat equation](/source/Heat_equation).

Especially easy are [multiplication operators](/source/Multiplication_operator), which are defined as multiplication by (the values of) a fixed function–the values of the function at each point correspond to the diagonal entries of a matrix.

## See also

- [Anti-diagonal matrix](/source/Anti-diagonal_matrix)

- [Banded matrix](/source/Banded_matrix)

- [Bidiagonal matrix](/source/Bidiagonal_matrix)

- [Diagonally dominant matrix](/source/Diagonally_dominant_matrix)

- [Diagonalizable matrix](/source/Diagonalizable_matrix)

- [Jordan normal form](/source/Jordan_normal_form)

- [Multiplication operator](/source/Multiplication_operator)

- [Tridiagonal matrix](/source/Tridiagonal_matrix)

- [Toeplitz matrix](/source/Toeplitz_matrix)

- [Toral Lie algebra](/source/Toral_Lie_algebra)

- [Circulant matrix](/source/Circulant_matrix)

## Notes

1. **[^](#cite_ref-1)** Proof: given the [elementary matrix](/source/Elementary_matrix) e i j {\displaystyle e_{ij}} , M e i j {\displaystyle Me_{ij}} is the matrix with only the *i*-th row of *M* and e i j M {\displaystyle e_{ij}M} is the square matrix with only the *M* *j*-th column, so the non-diagonal entries must be zero, and the *i*th diagonal entry much equal the *j*th diagonal entry.

1. **[^](#cite_ref-2)** Over more general rings, this does not hold, because one cannot always divide.

## References

1. **[^](#cite_ref-3)** ["Do Diagonal Matrices Always Commute?"](https://math.stackexchange.com/q/1697991). Stack Exchange. March 15, 2016. Retrieved August 4, 2018.

1. **[^](#cite_ref-4)** Sahami, Mehran (2009-06-15). [*Text Mining: Classification, Clustering, and Applications*](https://books.google.com/books?id=BnvYaYhMl-MC&pg=PA14). CRC Press. p. 14. [ISBN](/source/ISBN_(identifier)) [9781420059458](https://en.wikipedia.org/wiki/Special:BookSources/9781420059458).

1. **[^](#cite_ref-5)** ["Element-wise vector-vector multiplication in BLAS?"](https://stackoverflow.com/questions/7621520/element-wise-vector-vector-multiplication-in-blas). *stackoverflow.com*. 2011-10-01. Retrieved 2020-08-30.

1. **[^](#cite_ref-6)** Nearing, James (2010). ["Chapter 7.9: Eigenvalues and Eigenvectors"](http://www.physics.miami.edu/~nearing/mathmethods/operators.pdf) (PDF). [*Mathematical Tools for Physics*](http://www.physics.miami.edu/nearing/mathmethods). Dover Publications. [ISBN](/source/ISBN_(identifier)) [978-0486482125](https://en.wikipedia.org/wiki/Special:BookSources/978-0486482125). Retrieved January 1, 2012.

## Sources

- [Horn, Roger Alan](/source/Roger_Horn); [Johnson, Charles Royal](/source/Charles_Royal_Johnson) (1985), *Matrix Analysis*, [Cambridge University Press](/source/Cambridge_University_Press), [ISBN](/source/ISBN_(identifier)) [978-0-521-38632-6](https://en.wikipedia.org/wiki/Special:BookSources/978-0-521-38632-6)

v t e Matrix classes Explicitly constrained entries Alternant Anti-diagonal Anti-Hermitian Anti-symmetric Arrowhead Band Bidiagonal Bisymmetric Block-diagonal Block Block tridiagonal Boolean Cauchy Centrosymmetric Conference Complex Hadamard Copositive Diagonally dominant Diagonal Discrete Fourier Transform Elementary Equivalent Frobenius Generalized permutation Hadamard Hankel Hermitian Hessenberg Hollow Integer Logical Matrix unit Metzler Moore Nonnegative Pentadiagonal Permutation Persymmetric Polynomial Quaternionic Signature Skew-Hermitian Skew-symmetric Skyline Sparse Sylvester Symmetric Toeplitz Triangular Tridiagonal Vandermonde Walsh Z Constant Exchange Hilbert Identity Lehmer Of ones Pascal Pauli Redheffer Shift Zero Conditions on eigenvalues or eigenvectors Companion Convergent Defective Definite Diagonalizable Hurwitz-stable Positive-definite Stieltjes Satisfying conditions on products or inverses Congruent Idempotent or Projection Invertible Involutory Nilpotent Normal Orthogonal Unimodular Unipotent Unitary Totally unimodular Weighing With specific applications Adjugate Alternating sign Augmented Bézout Jabotinsky Cartan Circulant Cofactor Commutation Confusion Coxeter Distance Duplication and elimination Euclidean distance Fundamental (linear differential equation) Generator Gram Hessian Householder Jacobian Moment Payoff Pick Random Rotation Routh-Hurwitz Seifert Shear Similarity Symplectic Totally positive Transformation Used in statistics Centering Correlation Covariance Design Doubly stochastic Fisher information Hat Precision Stochastic Transition Used in graph theory Adjacency Biadjacency Degree Edmonds Incidence Laplacian Seidel adjacency Tutte Used in science and engineering Cabibbo–Kobayashi–Maskawa Density Fundamental (computer vision) Fuzzy associative Gamma Gell-Mann Hamiltonian Irregular Overlap S State transition Substitution Z (chemistry) Related terms Jordan normal form Linear independence Matrix exponential Matrix representation of conic sections Perfect matrix Pseudoinverse Row echelon form Wronskian Mathematics portal List of matrices Category:Matrices (mathematics)

---
Adapted from the Wikipedia article [Diagonal matrix](https://en.wikipedia.org/wiki/Diagonal_matrix) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Diagonal_matrix?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
