This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Create Special Matrices

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

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:


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:


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?