gallery
generate test matrices
Syntax
g = gallery(name, n1, ..., nn) g = gallery(3) g = gallery(5)
Arguments
- name
matrix name available in the following list:
"cauchy","circul","minij",molerand"ris- n1, ..., nn
double, scalars or vectors depend on the
nameof matrix- g
generated matrix
Description
g = gallery(name, n1, ..., nn) generates a name matrix. n1, ..., nn arguments
depend on the generated matrix (see *name* matrix sections below for more details).
g = gallery(3) is a badly conditioned 3-by-3 matrix.
g = gallery(5) creates a 5-by-5 matrix with an interesting eigenvalue problem.
Cauchy matrix
g = gallery("cauchy", x [, y]) creates a n-by-n Cauchy matrix. x and y are vectors of length n. If x is scalar, then it
will be interpreted as 1:x (same behavior for y).
The Cauchy matrix is defined by g(i,j) = 1/(x(i) + y(j)).
g = gallery("cauchy", x) computes g(i,j) = 1/(x(i) + x(j)).
Circulant matrix
g = gallery("circul", x) creates a n-by-n Circulant matrix whose first row is given by x. x is vector of length n. If x is scalar, then it
will be interpreted as 1:x.
A circulant matrix is a square matrix whose each row is obtained from the previous one by circular permutation (right shift):
.
Minij matrix
g = gallery("minij", n) creates a n-by-n Minij matrix. This matrix is symmetric positive definite matrix with
g(i,j) = min(i,j).
Moler matrix
g = gallery("moler", n) creates a n-by-n Moler matrix. This matrix is symmetric positive definite matrix with
g(i,j) = min(i,j)- 2 and g(i,i) = i.
Ris matrix
g = gallery("ris", n) creates a n-by-n Ris matrix. This matrix is symmetric n-by-n Hankel matrix with
g(i,j) = 0.5/(n - i - j + 1.5). Its eigenvalues have the property of clustering near +/- pi/2.
Examples
Cauchy matrix
g = gallery("cauchy", 3) g = gallery("cauchy", 1:3, 2:4)
--> g = gallery("cauchy", 3)
g = [3x3 double]
0.5 0.3333333 0.25
0.3333333 0.25 0.2
0.25 0.2 0.1666667
--> g = gallery("cauchy", 1:3, 2:4)
g = [3x3 double]
0.3333333 0.25 0.2
0.25 0.2 0.1666667
0.2 0.1666667 0.1428571
Circulant matrix
g = gallery("circul", 5) g = gallery("circul", [4 8 -1])
--> g = gallery("circul", 5)
g = [5x5 double]
1. 2. 3. 4. 5.
5. 1. 2. 3. 4.
4. 5. 1. 2. 3.
3. 4. 5. 1. 2.
2. 3. 4. 5. 1.
--> g = gallery("circul", [4 8 -1])
g = [3x3 double]
4. 8. -1.
-1. 4. 8.
8. -1. 4.
Minij matrix
g = gallery("minij", 5)
--> g = gallery("minij", 5)
g = [5x5 double]
1. 1. 1. 1. 1.
1. 2. 2. 2. 2.
1. 2. 3. 3. 3.
1. 2. 3. 4. 4.
1. 2. 3. 4. 5.
Moler matrix
g = gallery("moler", 5)
--> gallery("moler", 5)
ans = [5x5 double]
1. -1. -1. -1. -1.
-1. 2. 0. 0. 0.
-1. 0. 3. 1. 1.
-1. 0. 1. 4. 2.
-1. 0. 1. 2. 5.
Ris matrix
g = gallery("ris", 3)
--> g = gallery("ris", 3)
g = [3x3 double]
0.2 0.3333333 1.
0.3333333 1. -1.
1. -1. -0.3333333
See also
History
| Versão | Descrição |
| 2026.0.0 | Function added. |
| 2026.1.0 | Minij and Moler matrices added. |
| Report an issue | ||
| << frank | Elementary matrices | hadamard >> |