# How to Write Matrix in LaTeX?

## How to Write Matrix in LaTeX

The important feature of latex is to display mathematical and scientific formulas and equations in their original style and to make math equations look beautiful on our web or other important documents.

There are a few ways to enter math mode, however, the most common is

    $..inline math..$
or
$$..math in new line..$$

where the text within the dollar signs is in the math mode environment.

And the other method is by using the command,

$$and$$

There are equivalent ways of entering math mode for each of these methods as in the below example, however, the latter is now strongly preferred.

$$....$$ is equivalent to $....$

### Latex Code For Matrix

A matrix can be described as a rectangular array of numbers, symbols, or expressions that are arranged in rows and columns. A matrix in LaTeX can be generated with the help of a math environment for typesetting matrices.

For generating matrix in LaTeX we have to use the package amsmath by giving the command:

.wp-block-code {
max-width: 100%;
overflow: auto;
border: 0;
}

.wp-block-code > div {
width: 100%;
overflow: auto;
}
.wp-block-code > code {
width: 100%;
position: relative;
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
overflow-x: scroll;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
\usepackage{amsmath}

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$\begin{bmatrix} a & b & c \\ c & d & d\\ e & f & g \\ \end{bmatrix} \quad$$
\end{document}
Code language: JavaScript (javascript)

Output of the above code

$$\begin{bmatrix} a & b & c \\ c & d & d\\ e & f & g \\ \end{bmatrix} \quad$$

### Brackets in Latex

#### Latex pmatrix, bmatrix, vmatrix, Vmatrix

There can be various types of brackets to use in a matrix. Some of them are discussed below:

• p for parentheses
• b for square brackets
• v for verts
• B for curly braces
• V for double vertical bars.

Code Explanation:

• \begin{matrix} This command creates a matrix without brackets.
• \begin{pmatrix} This command creates a matrix with parenthesis.
• \begin{bmatrix} This command creates a matrix with square brackets.
• \begin{Bmatrix} This command creates a matrix with curly brackets.
• \begin{vmatrix} This command creates a matrix with a rectangular line boundary.
• \begin{Vmatrix} This command creates a matrix with double vertical bar brackets.

## How to write an m * n matrix in LaTeX

Latex Code for m * n Matrix

$$$$A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \vdots & \vdots\\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix}$$$$

Output of m * n matrix:

$$$$A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \vdots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix}$$$$

## How to Write 3 x 3 Matrix in LaTeX

#### 3 x 3 Matrix with parentheses:

$$A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}$$

$$A = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}$$

#### 3 x 3 Matrix with brackets:

$$B = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}$$

Output:

$$B = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}$$

#### 3 x 3 Matrix with no bracket

$$\begin{matrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{matrix}$$

Output:

\begin{matrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{matrix}

#### 3 x 3 Matrix with Vertical Bar | Determinant

$$\begin{vmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{vmatrix}$$

Output:

\begin{vmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33} \
\end{vmatrix}

#### 3 x 3 Latex matrix with curly brackets

$$\begin{Bmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{Bmatrix}$$

Output:

\begin{Bmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{Bmatrix}

#### Latex matrix with double vertical bar brackets

$$\begin{Vmatrix} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33} \end{Vmatrix}$$

Output:

\begin{Vmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{Vmatrix}

## How to Write 2 x 2 Matrix in LaTeX

Here are some examples of 2 x 2 matrix with pmatrix, bmatrix, vmatrix, Vmatrix.

\begin{matrix}
a & b\\
c & d
\end{matrix}

Output:

\begin{matrix}
a & b\\
c & d
\end{matrix}

### pmatrix

\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}

Output:

\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}

### bmatrix

\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}

Output:

\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}

### vmatrix

\begin{vmatrix}
a & b\\
c & d
\end{vmatrix}

Output:

\begin{vmatrix}
a & b\\
c & d
\end{vmatrix}

### Vmatrix

\begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}

Output:

\begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}