The following functions return famous matrix forms.
Construct a Hadamard matrix (Hn) of size n-by-n. The size n must be of the form 2^k * p in which p is one of 1, 12, 20 or 28. The returned matrix is normalized, meaning
Hn(:,1) == 1
andHn(1,:) == 1
.Some of the properties of Hadamard matrices are:
kron (Hm, Hn)
is a Hadamard matrix of size m-by-n.Hn * Hn' =
n* eye (
n)
.- The rows of Hn are orthogonal.
det (
A) <= abs (det (Hn))
for all A withabs (
A(i, j)) <= 1
.- Multiplying any row or column by -1 and the matrix will remain a Hadamard matrix.
Return the Hankel matrix constructed from the first column c, and (optionally) the last row r. If the last element of c is not the same as the first element of r, the last element of c is used. If the second argument is omitted, it is assumed to be a vector of zeros with the same size as c.
A Hankel matrix formed from an m-vector c, and an n-vector r, has the elements
H(i,j) = c(i+j-1), i+j-1 <= m; H(i,j) = r(i+j-m), otherwise
Return the Hilbert matrix of order n. The i,j element of a Hilbert matrix is defined as
H(i, j) = 1 / (i + j - 1)Hilbert matrices are close to being singular which make them difficult to invert with numerical routines. Comparing the condition number of a random matrix 5x5 matrix with that of a Hilbert matrix of order 5 reveals just how difficult the problem is.
cond (rand (5)) ⇒ 14.392 cond (hilb (5)) ⇒ 4.7661e+05See also: invhilb.
Return the inverse of the Hilbert matrix of order n. This can be computed exactly using
(i+j) /n+i-1\ /n+j-1\ /i+j-2\ 2 A(i,j) = -1 (i+j-1)( )( ) ( ) \ n-j / \ n-i / \ i-2 / = p(i) p(j) / (i+j-1)where
k /k+n-1\ /n\ p(k) = -1 ( ) ( ) \ k-1 / \k/The validity of this formula can easily be checked by expanding the binomial coefficients in both formulas as factorials. It can be derived more directly via the theory of Cauchy matrices. See J. W. Demmel, Applied Numerical Linear Algebra, p. 92.
Compare this with the numerical calculation of
inverse (hilb (n))
, which suffers from the ill-conditioning of the Hilbert matrix, and the finite precision of your computer's floating point arithmetic.See also: hilb.
Create an n-by-n magic square. A magic square is an arrangement of the integers
1:n^2
such that the row sums, column sums, and diagonal sums are all equal to the same value.Note: n must be greater than 2 for the magic square to exist.
Return the Pascal matrix of order n if t
= 0
. t defaults to 0. Return the pseudo-lower triangular Cholesky factor of the Pascal matrix if t= 1
(The sign of some columns may be negative). This matrix is its own inverse, that ispascal (
n, 1) ^ 2 == eye (
n)
. If t= -1
, return the true Cholesky factor with strictly positive values on the diagonal. If t= 2
, return a transposed and permuted version ofpascal (
n, 1)
, which is the cube root of the identity matrix. That is,pascal (
n, 2) ^ 3 == eye (
n)
.See also: chol.
Return the Rosser matrix. This is a difficult test case used to evaluate eigenvalue algorithms.
Return the Toeplitz matrix constructed from the first column c, and (optionally) the first row r. If the first element of r is not the same as the first element of c, the first element of c is used. If the second argument is omitted, the first row is taken to be the same as the first column.
A square Toeplitz matrix has the form:
c(0) r(1) r(2) ... r(n) c(1) c(0) r(1) ... r(n-1) c(2) c(1) c(0) ... r(n-2) . . . . . . . . . . . . . . . c(n) c(n-1) c(n-2) ... c(0)See also: hankel.
Return the Vandermonde matrix whose next to last column is c. If n is specified, it determines the number of columns; otherwise, n is taken to be equal to the length of c.
A Vandermonde matrix has the form:
c(1)^(n-1) ... c(1)^2 c(1) 1 c(2)^(n-1) ... c(2)^2 c(2) 1 . . . . . . . . . . . . . . . c(n)^(n-1) ... c(n)^2 c(n) 1See also: polyfit.