Matrices

You can create and calculate using matrices in the Desmos Graphing Calculator, Geometry Tool, 3D Calculator, and Notebook.

Watch the video for an introduction to using Matrices in Desmos, and read on to learn more.

 

Matrices are a new feature, so if you run into any bugs, please reach out to us at support@desmos.com.

 

Create a Matrix

To create your first matrix, enter matrix in a new expression line. This will generate a new 2x2 matrix filled with zeros. Click, tab, or use your arrow keys to move between cells to fill in your own values.

To define a new matrix with specific dimensions, you can use the syntax \(\mathbf{\#ab}\), where \(a\) is the number of rows, and \(b\) is the number of columns. For example, typing \(\mathbf{\#43}\) will create a 4x3 matrix.

To add or remove rows and columns to your matrix, click and drag the corner Matrix icon, or tab to the corner and then use your arrow keys to adjust.

Typing “matrix” into an expression line to generate a 2x2 matrix. In the next line, typing “#43” to create a 4x3 matrix and then dragging the corner to extend it. Gif.

 

Matrix Operations and Syntax

You can perform operations on a matrix directly or by referencing matrices defined by variables. You can multiply by a scalar or another matrix, add or subtract matrices, or find inverses.

Some matrix functions require specific conditions. For example, multiplied matrices must have compatible dimensions, you can only find the determinant of square matrices, and you can’t invert a singular matrix.

Four expression lines in the calculator. The first line shows the multiplication of a 2x2 matrix and 2x1 matrix, resulting in a 2x1 matrix. The second line shows a matrix defined as A. The third line shows the expression 2A, which scales the matrix by 2. The third shows A raised to negative one, which finds the inverse of the matrix. Screenshot.

You can use additional commands to extract elements of your matrix or to define new matrices.

To extract the single element in row \(a\) and column \(b\) of a matrix \(M\), use the syntax \(\mathbf{M[a;b]}\). For example, typing \(\mathbf{M[2;3]}\) will return the element in the second row and third column.

You can call multiple rows or columns at a time using this syntax using commas, and if you leave one of these elements blank, the calculator will return the full row or column.

Alternatively, you can extract entire rows or columns using the syntax rows\(\mathbf{(M)}\) or columns\(\mathbf{(M)}\).

Five expression lines in the calculator. The first shows a 3x3 matrix defined as M. The second shows M[2;3], which returns the element in row 2 and column 3. The third shows M[1;2;], which returns the first two rows of the matrix as a separate matrix. The fourth shows columns(M), which returns a 3-element list. The fifth shows rows(M)[1], which returns the first row of the matrix as a separate matrix. Screenshot.

To create a matrix with a specific structure, you can use list comprehension.

Take the following expression as an example: \(a+b\) for \(a=[1…3];b=[1…4].\)

By separating the two variable lists with a semicolon, the calculator recognizes this expression as a matrix. The first list designates the number of rows, and the second indicates the number of columns. The initial expression, \(a+b\), determines the value assigned to each position in terms of row and column.

You can use this strategy to create an identity matrix by assigning ones for the diagonal where the row and column numbers are the same.

Three expression lines. The first two show examples of using matrices and list comprehension. The third line defines the variable n. Screenshot.

 

More Ways to Use Matrices

Points

Three expression lines. The first defines a 2x2 matrix as A. The second defines another 2x2 matrix as B. The third shows a block matrix built with A and B. Screenshot.

You can multiply a matrix with appropriate dimensions by a 2D or 3D point to transform it, so you can rotate, scale, or reflect points. Explore our Matrix Point Transformations example graph.

Block Matrices

Three expression lines. The first shows a 2x2 matrix multiplied by a 2D point. The second line defines a point P. The third line shows a matrix multiplied by P. Screenshot.

A matrix entry can itself be a matrix, so you can build block matrices out of matrices you've already defined.

 

Supported Functions

   Function Try typing... This function...
determinant det\(\mathbf{(A)}\) calculates the determinant of a square matrix.
trace trace\(\mathbf{(A)}\) calculates the sum of the diagonal of a square matrix.
reduced row echelon format rref\(\mathbf{(A)}\) reduces a matrix to row echelon form.
rank rank\(\mathbf{(A)}\) calculates the maximum number of linearly independent rows or columns of a matrix.
rows rows\(\mathbf{(A)}\) returns a list of row matrices.
columns columns\(\mathbf{(A)}\)

returns a list of column matrices.

transpose \(\mathbf{A^{T}}\) switches the rows and columns of a matrix.
matrix template

matrix

creates a 2x2 matrix.
hash

\(\mathbf{\#24}\)

creates a matrix with the given row and column dimensions.

So, \(\#24\) will give a 2x4 matrix.

semicolon

\(\mathbf{A[2;4]}\)

separates a matrix row and column dimensions when referencing a matrix element, column, or row.

So, \(A[2;4]\) will give the entry in the second row and fourth column of the matrix.

inverse \(\mathbf{A^{-1}}\) finds the inverse of a non-singular, square matrix.

 

Learn More

Please write in with any questions or feedback to support@desmos.com.