# Main diagonal

In linear algebra, the main diagonal (sometimes principal diagonal, primary diagonal, leading diagonal, major diagonal, or good diagonal) of a matrix $A$ is the list of entries $a_{i,j}$ where $i=j$. All off-diagonal elements are zero in a diagonal matrix. The following four matrices have their main diagonals indicated by red ones:
${\begin{bmatrix}\color {red}{1}&0&0\\0&\color {red}{1}&0\\0&0&\color {red}{1}\end{bmatrix}}\qquad {\begin{bmatrix}\color {red}{1}&0&0&0\\0&\color {red}{1}&0&0\\0&0&\color {red}{1}&0\end{bmatrix}}\qquad {\begin{bmatrix}\color {red}{1}&0&0\\0&\color {red}{1}&0\\0&0&\color {red}{1}\end{bmatrix}}\qquad {\begin{bmatrix}\color {red}{1}&0&0&0\\0&\color {red}{1}&0&0\\0&0&\color {red}{1}&0\\0&0&0&\color {red}{1}\end{bmatrix}}$

## Square matrices

For a square matrix, the diagonal (or main diagonal or principal diagonal) is the diagonal line of entries running from the top-left corner to the bottom-right corner. For a matrix $A$ with row index specified by $i$ and column index specified by $j$, these would be entries $A_{ij}$ with $i=j$. For example, the identity matrix can be defined as having entries of 1 on the main diagonal and zeroes elsewhere:
    ${\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}}$
The trace of a matrix is the sum of the diagonal elements.
The top-right to bottom-left diagonal is sometimes described as the minor diagonal or antidiagonal.
The off-diagonal entries are those not on the main diagonal. A diagonal matrix is one whose off-diagonal entries are all zero.
A superdiagonal entry is one that is directly above and to the right of the main diagonal. Just as diagonal entries are those $A_{ij}$ with $j=i$, the superdiagonal entries are those with $j=i+1$. For example, the non-zero entries of the following matrix all lie in the superdiagonal:
    ${\begin{pmatrix}0&2&0\\0&0&3\\0&0&0\end{pmatrix}}$
Likewise, a subdiagonal entry is one that is directly below and to the left of the main diagonal, that is, an entry $A_{ij}$ with $j=i-1$. General matrix diagonals can be specified by an index $k$ measured relative to the main diagonal: the main diagonal has $k=0$; the superdiagonal has $k=1$; the subdiagonal has $k=-1$; and in general, the $k$-diagonal consists of the entries $A_{ij}$ with $j=i+k$.
A banded matrix is one for which its non-zero elements are restricted to a diagonal band. A tridiagonal matrix has only the main diagonal, superdiagonal, and subdiagonal entries as non-zero.

## Antidiagonal

The antidiagonal (sometimes counter diagonal, secondary diagonal (*), trailing diagonal, minor diagonal, off diagonal, or bad diagonal) of an order $N$ square matrix $B$ is the collection of entries $b_{i,j}$ such that $i+j=N+1$ for all $1\leq i,j\leq N$. That is, it runs from the top right corner to the bottom left corner.
    ${\begin{bmatrix}0&0&\color {red}{1}\\0&\color {red}{1}&0\\\color {red}{1}&0&0\end{bmatrix}}$
(*) Secondary (as well as trailing, minor and off) diagonals very often also mean the (a.k.a. k-th) diagonals parallel to the main or principal diagonals, i.e., $A_{i,\,i\pm k}$ for some nonzero k =1, 2, 3, ... More generally and universally, the off diagonal elements of a matrix are all elements not on the main diagonal, i.e., with distinct indices i ≠ j.