Elements of the diagonal matrix will be along the diagonal. All the other positions except the diagonal position of the matrix will be filled by zero.

```
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$
\begin{bmatrix}
a_{1} & & & \\
& a_{2} & & \\
& & \ddots & \\
& & & a_{3}
\end{bmatrix}
$$
\end{document}
```

**Output :**

And diagonal matrix is only valid in the case of a square matrix.

## Use physics package for diagonal matrix

In Latex, there are various arguments within the physics package that allow you to easily represent the diagnostic matrix in a variety of ways.

```
\documentclass{article}
\usepackage{physics}
\begin{document}
$$
\mqty[ a_{1} & 0 & 0\\ 0 & a_{2} & 0\\ 0 & 0 & a_{3} ]
$$
\end{document}
```

**Output :**

Second, you can use the \dmat command. However, this \dmat command must be passed as an argument in the \mqty command without using Direct.

```
\documentclass{article}
\usepackage{physics}
\begin{document}
$$ \mqty[\dmat{1,2,3,4}] $$
\end{document}
```

**Output :**

And with that, the elements of the diagonal matrix have to be passed into the \dmat command.

To fill in any position other than the diagonal position of the matrix by zero, you need to pass 0 in the optional argument with the \dmat command.

```
\documentclass{article}
\usepackage{physics}
\begin{document}
$$ \mqty[\dmat[0]{1,2,3,4}] $$
\end{document}
```

**Output :**

If you want to arrange the elements of the matrix along the inverse diagonal you need to use \admat instead of \dmat.

```
\documentclass{article}
\usepackage{physics}
\begin{document}
$$ \mqty[\admat{1,2,3,4}] $$
$$ \mqty[\admat[0]{1,2,3,4}] $$
\end{document}
```

**Output :**