test_matrix, a MATLAB code which defines test matrices for which the condition number, determinant, eigenvalues, eigenvectors, inverse, null vectors, P*L*U factorization or linear system solution are known. Examples include the Fibonacci, Hilbert, Redheffer, Vandermonde, Wathen and Wilkinson matrices.

A wide range of matrix dimensions, forms and properties are available. These matrices may be useful in testing an algorithm for correctness on a variety of problems.

Many of the matrices can be rectangular, with the user specifying the number of rows and columns. Almost all the matrices can be made of arbitrary size, with the user specifying the dimension.

Many different matrix zero structures are available, including diagonal, bidiagonal, tridiagonal, pentadiagonal, banded, upper and lower triangular, and Hessenberg.

Many different matrix symmetry patterns are available, including symmetric, antisymmetric, persymmetric, circulant, Toeplitz, and Hankel.

Matrices are available with known inverses, condition numbers, determinants, rank, eigenvalues, and characteristic polynomials. Other matrix properties include positive definiteness, positivity, zero/one, and adjacency matrices.

Many of the matrices come from a MATLAB M file collection developed by Nicholas Higham, Department of Mathematics, University of Manchester.

An earlier version of the collection is available, again as MATLAB M files, in ACM TOMS Algorithm 694, in the TOMS directory of the NETLIB web site.

Many of these matrices, and many other matrices, are available at https://math.nist.gov, the Matrix Market web site.


The information on this web page is distributed under the MIT license.


test_matrix is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

Related Data and Programs:


arpack_test, a MATLAB code which uses Arnoldi methods to compute some eigenvalues and eigenvectors of matrices, which may be very large.

cg, a MATLAB code which implements a simple version of the conjugate gradient (CG) method for solving a system of linear equations of the form A*x=b, suitable for situations in which the matrix A is positive definite (only real, positive eigenvalues) and symmetric.

condition, a MATLAB code which implements methods of computing or estimating the condition number of a matrix.

jacobi_eigenvalue, a MATLAB code which implements the jacobi iteration for the iterative determination of the eigenvalues and eigenvectors of a real symmetric matrix.

jordan_matrix, a MATLAB code which returns a random matrix in Jordan canonical form.

levenshtein_matrix, a MATLAB code which returns the Levenshtein distance matrix defined by two strings.

magic_matrix, a MATLAB code which computes a magic matrix, for any odd order n, such that all rows and columns have the same sum.

matrix_exponential, a MATLAB code which demonstrates some simple approaches to the problem of computing the exponential of a matrix.

monopoly_matrix, a MATLAB code which computes the adjacency and transition matrices for the game of Monopoly.

plasma_matrix, a MATLAB code which sets up a matrix associated with a problem in plasma physics.

polynomial_conversion, a MATLAB code which converts representations of a polynomial between monomial, Bernstein, Chebyshev, Hermite, Lagrange, Laguerre and other forms.

risk_matrix, a MATLAB code which computes the transition and adjacency matrix for the game of RISK.

snakes_matrix, a MATLAB code which computes the transition matrix for Snakes and Ladders.

tennis_matrix, a MATLAB code which computes the transition matrix for a game of tennis, which has 17 distinct states.

test_eigen, a MATLAB code which implements test matrices for eigenvalue analysis.

test_matrix_exponential, a MATLAB code which defines a set of test cases for computing the matrix exponential.

usa_matrix, a MATLAB code which defines the adjacency matrix for US states, using a variety of matrix formats.

wathen_matrix, a MATLAB code which compares storage schemes (full, banded, sparse triplet, sparse) and solution strategies (A\x, Linpack, conjugate gradient) for linear systems involving the Wathen matrix, which can arise when solving a problem using the finite element method (FEM).

web_matrix, a MATLAB code which stores sample matrices describing a web page network. These matrices are typically very sparse, and the examples here are stored using the sparse triplet (ST) format. They can be used to demonstrate pagerank and other graph algorithms.

wishart_matrix, a MATLAB code which produces sample matrices from the Wishart or Bartlett distributions, useful for sampling random covariance matrices.

Source Code:

Last revised on 05 April 2024.