Documentation Center

  • Trial Software
  • Product Updates

Create Special Matrices

MuPAD® provides functions for creating special types of matrices such as identity, diagonal, Hilbert, Toeplitz, and other matrices. For example, create the 3×3 identity matrix:

matrix::identity(3)

Now, create the 3×3 diagonal matrix with the number 5 on the diagonal:

matrix(3, 3, 5, Diagonal)

To create a matrix containing variables or arithmetical expressions, always use a list to specify matrix elements. For example, when creating the 3×3 diagonal matrix with the variable x on its main diagonal, specify the diagonal elements in a list [x, x, x]. As a shortcut for creating this list, you can use the sequence generator $:

matrix(3, 3, [x $ 3], Diagonal)

To create special matrices such as Hilbert, Toeplitz, Pascal, or Vandermonde matrices, use the appropriate function of the linalg library. For example, to create the 4×4 Hilbert matrix, use the linalg::hilbert function:

linalg::hilbert(3)

To create a matrix of random numbers, use the linalg::randomMatrix function. For example, create a matrix of random integer numbers:

linalg::randomMatrix(3, 4, Dom::Integer)

Now, create a matrix that has random rational numbers on the main diagonal and zeros everywhere else:

linalg::randomMatrix(3, 3, Diagonal, Dom::Rational)

Was this topic helpful?