GNU Octave: Famous Matrices

Previous: Special Utility Matrices, Up: Matrix Manipulation [Contents][Index]

### 16.4 Famous Matrices

The following functions return famous matrix forms.

Function File: gallery (name)
Function File: gallery (name, args)

  Create interesting matrices for testing.

Function File: c = gallery ("cauchy", x)
Function File: c = gallery ("cauchy", x, y)

  Create a Cauchy matrix.

Function File: c = gallery ("chebspec", n)
Function File: c = gallery ("chebspec", n, k)

  Create a Chebyshev spectral differentiation matrix.

Function File: c = gallery ("chebvand", p)
Function File: c = gallery ("chebvand", m, p)

  Create a Vandermonde-like matrix for the Chebyshev polynomials.

Function File: a = gallery ("chow", n)
Function File: a = gallery ("chow", n, alpha)
Function File: a = gallery ("chow", n, alpha, delta)

  Create a Chow matrix – a singular Toeplitz lower Hessenberg matrix.

Function File: c = gallery ("circul", v)

  Create a circulant matrix.

Function File: a = gallery ("clement", n)
Function File: a = gallery ("clement", n, k)

  Create a tridiagonal matrix with zero diagonal entries.

Function File: c = gallery ("compar", a)
Function File: c = gallery ("compar", a, k)

  Create a comparison matrix.

Function File: a = gallery ("condex", n)
Function File: a = gallery ("condex", n, k)
Function File: a = gallery ("condex", n, k, theta)

  Create a ‘counterexample’ matrix to a condition estimator.

Function File: a = gallery ("cycol", [m n])
Function File: a = gallery ("cycol", n)
Function File: a = gallery (…, k)

  Create a matrix whose columns repeat cyclically.

Function File: [c, d, e] = gallery ("dorr", n)
Function File: [c, d, e] = gallery ("dorr", n, theta)
Function File: a = gallery ("dorr", …)

  Create a diagonally dominant, ill conditioned, tridiagonal matrix.

Function File: a = gallery ("dramadah", n)
Function File: a = gallery ("dramadah", n, k)

  Create a (0, 1) matrix whose inverse has large integer entries.

Function File: a = gallery ("fiedler", c)

  Create a symmetric Fiedler matrix.

Function File: a = gallery ("forsythe", n)
Function File: a = gallery ("forsythe", n, alpha)
Function File: a = gallery ("forsythe", n, alpha, lambda)

  Create a Forsythe matrix (a perturbed Jordan block).

Function File: f = gallery ("frank", n)
Function File: f = gallery ("frank", n, k)

  Create a Frank matrix (ill conditioned eigenvalues).

Function File: c = gallery ("gcdmat", n)

  Create a greatest common divisor matrix.

  c is an n-by-n matrix whose values correspond to the greatest common divisor of its coordinate values, i.e., c(i,j) correspond `gcd (i, j)`.

Function File: a = gallery ("gearmat", n)
Function File: a = gallery ("gearmat", n, i)
Function File: a = gallery ("gearmat", n, i, j)

  Create a Gear matrix.

Function File: g = gallery ("grcar", n)
Function File: g = gallery ("grcar", n, k)

  Create a Toeplitz matrix with sensitive eigenvalues.

Function File: a = gallery ("hanowa", n)
Function File: a = gallery ("hanowa", n, d)

  Create a matrix whose eigenvalues lie on a vertical line in the complex plane.

Function File: v = gallery ("house", x)
Function File: [v, beta] = gallery ("house", x)

  Create a householder matrix.

Function File: a = gallery ("integerdata", imax, [M N …], j)
Function File: a = gallery ("integerdata", imax, M, N, …, j)
Function File: a = gallery ("integerdata", [imin, imax], [M N …], j)
Function File: a = gallery ("integerdata", [imin, imax], M, N, …, j)
Function File: a = gallery ("integerdata", …, "class")

  Create a matrix with random integers in the range [1, imax]. If imin is given then the integers are in the range [imin, imax].

  The second input is a matrix of dimensions describing the size of the output. The dimensions can also be input as comma-separated arguments.

  The input j is an integer index in the range [0, 2^32-1]. The values of the output matrix are always exactly the same (reproducibility) for a given size input and j index.

  The final optional argument determines the class of the resulting matrix. Possible values for class: `"uint8"`, `"uint16"`, `"uint32"`, `"int8"`, `"int16"`, int32", `"single"`, `"double"`. The default is `"double"`.

Function File: a = gallery ("invhess", x)
Function File: a = gallery ("invhess", x, y)

  Create the inverse of an upper Hessenberg matrix.

Function File: a = gallery ("invol", n)

  Create an involutory matrix.

Function File: a = gallery ("ipjfact", n)
Function File: a = gallery ("ipjfact", n, k)

  Create an Hankel matrix with factorial elements.

Function File: a = gallery ("jordbloc", n)
Function File: a = gallery ("jordbloc", n, lambda)

  Create a Jordan block.

Function File: u = gallery ("kahan", n)
Function File: u = gallery ("kahan", n, theta)
Function File: u = gallery ("kahan", n, theta, pert)

  Create a Kahan matrix (upper trapezoidal).

Function File: a = gallery ("kms", n)
Function File: a = gallery ("kms", n, rho)

  Create a Kac-Murdock-Szego Toeplitz matrix.

Function File: b = gallery ("krylov", a)
Function File: b = gallery ("krylov", a, x)
Function File: b = gallery ("krylov", a, x, j)

  Create a Krylov matrix.

Function File: a = gallery ("lauchli", n)
Function File: a = gallery ("lauchli", n, mu)

  Create a Lauchli matrix (rectangular).

Function File: a = gallery ("lehmer", n)

  Create a Lehmer matrix (symmetric positive definite).

Function File: t = gallery ("lesp", n)

  Create a tridiagonal matrix with real, sensitive eigenvalues.

Function File: a = gallery ("lotkin", n)

  Create a Lotkin matrix.

Function File: a = gallery ("minij", n)

  Create a symmetric positive definite matrix MIN(i,j).

Function File: a = gallery ("moler", n)
Function File: a = gallery ("moler", n, alpha)

  Create a Moler matrix (symmetric positive definite).

Function File: [a, t] = gallery ("neumann", n)

  Create a singular matrix from the discrete Neumann problem (sparse).

Function File: a = gallery ("normaldata", [M N …], j)
Function File: a = gallery ("normaldata", M, N, …, j)
Function File: a = gallery ("normaldata", …, "class")

  Create a matrix with random samples from the standard normal distribution (mean = 0, std = 1).

  The first input is a matrix of dimensions describing the size of the output. The dimensions can also be input as comma-separated arguments.

  The input j is an integer index in the range [0, 2^32-1]. The values of the output matrix are always exactly the same (reproducibility) for a given size input and j index.

  The final optional argument determines the class of the resulting matrix. Possible values for class: `"single"`, `"double"`. The default is `"double"`.

Function File: q = gallery ("orthog", n)
Function File: q = gallery ("orthog", n, k)

  Create orthogonal and nearly orthogonal matrices.

Function File: a = gallery ("parter", n)

  Create a Parter matrix (a Toeplitz matrix with singular values near pi).

Function File: p = gallery ("pei", n)
Function File: p = gallery ("pei", n, alpha)

  Create a Pei matrix.

Function File: a = gallery ("Poisson", n)

  Create a block tridiagonal matrix from Poisson’s equation (sparse).

Function File: a = gallery ("prolate", n)
Function File: a = gallery ("prolate", n, w)

  Create a prolate matrix (symmetric, ill-conditioned Toeplitz matrix).

Function File: h = gallery ("randhess", x)

  Create a random, orthogonal upper Hessenberg matrix.

Function File: a = gallery ("rando", n)
Function File: a = gallery ("rando", n, k)

  Create a random matrix with elements -1, 0 or 1.

Function File: a = gallery ("randsvd", n)
Function File: a = gallery ("randsvd", n, kappa)
Function File: a = gallery ("randsvd", n, kappa, mode)
Function File: a = gallery ("randsvd", n, kappa, mode, kl)
Function File: a = gallery ("randsvd", n, kappa, mode, kl, ku)

  Create a random matrix with pre-assigned singular values.

Function File: a = gallery ("redheff", n)

  Create a zero and ones matrix of Redheffer associated with the Riemann hypothesis.

Function File: a = gallery ("riemann", n)

  Create a matrix associated with the Riemann hypothesis.

Function File: a = gallery ("ris", n)

  Create a symmetric Hankel matrix.

Function File: a = gallery ("smoke", n)
Function File: a = gallery ("smoke", n, k)

  Create a complex matrix, with a ‘smoke ring’ pseudospectrum.

Function File: t = gallery ("toeppd", n)
Function File: t = gallery ("toeppd", n, m)
Function File: t = gallery ("toeppd", n, m, w)
Function File: t = gallery ("toeppd", n, m, w, theta)

  Create a symmetric positive definite Toeplitz matrix.

Function File: p = gallery ("toeppen", n)
Function File: p = gallery ("toeppen", n, a)
Function File: p = gallery ("toeppen", n, a, b)
Function File: p = gallery ("toeppen", n, a, b, c)
Function File: p = gallery ("toeppen", n, a, b, c, d)
Function File: p = gallery ("toeppen", n, a, b, c, d, e)

  Create a pentadiagonal Toeplitz matrix (sparse).

Function File: a = gallery ("tridiag", x, y, z)
Function File: a = gallery ("tridiag", n)
Function File: a = gallery ("tridiag", n, c, d, e)

  Create a tridiagonal matrix (sparse).

Function File: t = gallery ("triw", n)
Function File: t = gallery ("triw", n, alpha)
Function File: t = gallery ("triw", n, alpha, k)

  Create an upper triangular matrix discussed by Kahan, Golub and Wilkinson.

Function File: a = gallery ("uniformdata", [M N …], j)
Function File: a = gallery ("uniformdata", M, N, …, j)
Function File: a = gallery ("uniformdata", …, "class")

  Create a matrix with random samples from the standard uniform distribution (range [0,1]).

  The first input is a matrix of dimensions describing the size of the output. The dimensions can also be input as comma-separated arguments.

  The input j is an integer index in the range [0, 2^32-1]. The values of the output matrix are always exactly the same (reproducibility) for a given size input and j index.

  The final optional argument determines the class of the resulting matrix. Possible values for class: `"single"`, `"double"`. The default is `"double"`.

Function File: a = gallery ("wathen", nx, ny)
Function File: a = gallery ("wathen", nx, ny, k)

  Create the Wathen matrix.

Function File: [a, b] = gallery ("wilk", n)

  Create various specific matrices devised/discussed by Wilkinson.

Function File: hadamard (n)

  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` and `Hn(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 with `abs (A(i, j)) <= 1`.
  - Multiplying any row or column by -1 and the matrix will remain a Hadamard matrix.

  See also: compan, hankel, toeplitz.

Function File: hankel (c)
Function File: hankel (c, r)

  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

  See also: hadamard, toeplitz.

Function File: hilb (n)

  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+05

  See also: invhilb.

Function File: invhilb (n)

  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.

Function File: magic (n)

  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.

Function File: pascal (n)
Function File: pascal (n, t)

  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 is `pascal (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 of `pascal (n, 1)`, which is the cube root of the identity matrix. That is, `pascal (n, 2) ^ 3 == eye (n)`.

  See also: chol.

Function File: rosser ()

  Return the Rosser matrix. This is a difficult test case used to evaluate eigenvalue algorithms.

  See also: wilkinson, eig.

Function File: toeplitz (c)
Function File: toeplitz (c, r)

  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.

Function File: vander (c)
Function File: vander (c, n)

  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)  1

  See also: polyfit.

Function File: wilkinson (n)

  Return the Wilkinson matrix of order n. Wilkinson matrices are symmetric and tridiagonal with pairs of nearly, but not exactly, equal eigenvalues. They are useful in testing the behavior and performance of eigenvalue solvers.

  See also: rosser, eig.

Previous: Special Utility Matrices, Up: Matrix Manipulation [Contents][Index]