Documentation Center

  • Trial Software
  • Product Updates

Create Matrices

MuPAD® supports creating and operating on vectors and multidimensional matrices. Vectors and matrices in MuPAD can contain arbitrary MuPAD objects: numbers, variables, arithmetical expressions, and so on. The simplest way to create a matrix is to use the matrix command:

matrix([[1, 2, 3], [4, 5, 6]])

When creating a matrix, you can explicitly specify its dimensions. If you specify matrix dimensions, you can use a flat list to specify all elements of a matrix. The matrix command takes the entries from the flat list and generates a matrix, row by row. For example, create the following 2×3 matrix:

matrix(2, 3, [1, 2, 3, 4, 5, 6])

Using the same list of elements, create the following 3 ×2 matrix:

matrix(3, 2, [1, 2, 3, 4, 5, 6])

If you specify matrix dimensions, and then enter rows or columns shorter than the declared dimensions, MuPAD pads the matrix with zero elements:

matrix(3, 3, [[1, 2, 3], [4, 5, 6]])

matrix(3, 3, [[1, 2, 3], [4]])

To create a matrix of zeros, specify matrix dimensions and omit specifying elements:

matrix(3, 2)

If you use a flat list, MuPAD cannot determine where to put zeros and, therefore, issues an error:

matrix(3, 3, [1, 2, 3, 4])
Error: The number of list entries does not match matrix row dimension. [(Dom::Matrix(Dom::ExpressionField()))::mkSparse]

If you specify matrix dimensions, and then enter rows or columns longer than the declared dimensions, MuPAD also issues an error:

A := matrix(2, 3, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Error: The number of list entries does not match matrix row dimension. [(Dom::Matrix(Dom::ExpressionField()))::mkSparse]

The matrix command creates an object of the type Dom::Matrix():

A := matrix([[1, 2, 3], [4, 5, 6]]):
type(A)

Was this topic helpful?