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.
Write Matrices in Latex
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,
\begin{equation} and \end{equation}
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:
\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)
Note: If you are using online Latex code editor then copy only the equation part.
Output of the above code
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
$$\begin{equation}
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}
\end{equation}
$$
Output of m * n matrix:
How to Write 3 x 3 Matrix in LaTeX
3 x 3 Matrix with parentheses:
\begin{equation} A =
\begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{pmatrix}
\end{equation}
3 x 3 Matrix with brackets:
\begin{equation} B =
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}
\end{equation}
Output:
3 x 3 Matrix with no bracket
\begin{equation}
\begin{matrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{matrix}
\end{equation}
Output:
3 x 3 Matrix with Vertical Bar | Determinant
\begin{equation}
\begin{vmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{vmatrix}
\end{equation}
Output:
3 x 3 Latex matrix with curly brackets
\begin{equation}
\begin{Bmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{Bmatrix}
\end{equation}
Output:
Latex matrix with double vertical bar brackets
\begin{equation}
\begin{Vmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{Vmatrix}
\end{equation}
Output:
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:
pmatrix
\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}
Output:
bmatrix
\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}
Output:
vmatrix
\begin{vmatrix}
a & b\\
c & d
\end{vmatrix}
Vmatrix
\begin{Vmatrix}
a & b\\
c & d
\end{Vmatrix}
End Thanks!