+3 votes
67 views
in Office by (242k points)
reopened
LaTeX: create a matrix - this is how it works

1 Answer

+4 votes
by (1.6m points)
 
Best answer

Create a matrix using an array environment
Create a matrix using the amsmath package

Do you need matrices for your scientific work or mathematical calculations in LaTeX? Here's how it works..

image image

In mathematics, a matrix represents a rectangular arrangement of elements. Arithmetic operations can then take place with these elements and are a key concept of linear algebra. LaTeX is a popular programming language, especially in the field of mathematics , to map complex formulas and calculations. How to successfully display matrices in LaTeX with the help of arrays and the amsmaths package, you will learn in this tipps + tricks article.

Create a matrix using an array environment

Within the LaTeX standard, a matrix can be inserted into your document using an array environment. The definition of the required columns and their alignment must, however, be determined in advance. In addition, the bracketing of the matrix must be defined. Otherwise the number array would be shown without brackets, i.e. not represent a matrix. The whole thing can be done very quickly with a few commands. We use the identity matrix in our example because it is common knowledge. You can create a normal number array as follows:

$\begin{array}{rrr}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}$

The commands mean in detail:

  • $ opens the math environment and closes it with another $ sign
  • \ begin {array} or \ end {array} defines the beginning or the end of a new environment, in this case the array environment
  • {rrr} specifies three columns that are right- justified
  • & separates the individual columns from each other
  • \\ creates a line break

Based on this example, you can define a matrix with the appropriate brackets. To do this, you have to enter the brackets with the commands / left and / right after opening and before closing the math environment in the LaTeX code.

Round brackets:

$\left( \begin{array}{rrr}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}\right)$

Square brackets:

$\left[ \begin{array}{rrr}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{array}\right]$

Create a matrix using the amsmath package

When you initially import the amsmath package into your document, you have six different environments for matrices. To do this, you must first include \ usepackage {amsmath} in the preamble . The number of columns is recognized automatically, which is an important advantage over the number array. Here we show you the minimal example for a matrix without brackets and then all options:

without brackets:

$\begin{matrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
\end{matrix}$

Replace the matrix command above with the following options for the appropriate output:

  1. matrix > without brackets
  2. pmatrix > round brackets
  3. bmatrix > square brackets
  4. Bmatrix > curly brackets
  5. vmatrix > vertical bar matrix
  6. Vmatrix > double vertical bar matrix
image

...