Examples

Getting started

Generate a Hilbert matrix and a circulant matrix:

matrixdepot("hilb", 4)
4×4 Matrix{Float64}:
 1.0       0.5       0.333333  0.25
 0.5       0.333333  0.25      0.2
 0.333333  0.25      0.2       0.166667
 0.25      0.2       0.166667  0.142857
matrixdepot("circul", 5)
5×5 Matrix{Float64}:
 1.0  2.0  3.0  4.0  5.0
 5.0  1.0  2.0  3.0  4.0
 4.0  5.0  1.0  2.0  3.0
 3.0  4.0  5.0  1.0  2.0
 2.0  3.0  4.0  5.0  1.0

Rectangular matrices and other element types are supported where the generator allows:

matrixdepot("hilb", Float16, 5, 3)
5×3 Matrix{Float16}:
 1.0     0.5     0.3333
 0.5     0.3333  0.25
 0.3333  0.25    0.2
 0.25    0.2     0.1666
 0.2     0.1666  0.1428

Select matrices by group:

mdlist(:inverse & :illcond & :symmetric)
7-element Vector{String}:
 "cauchy"
 "hilb"
 "invhilb"
 "kms"
 "moler"
 "pascal"
 "pei"

and use them in tests:

for name in ["lehmer", "cauchy", "hilb"]
    A = matrixdepot(name, 6)
    F = lu(A)
    println("1-norm error for $name: ", norm(A[F.p, :] - F.L * F.U, 1))
end
1-norm error for lehmer: 0.0
1-norm error for cauchy: 4.163336342344337e-17
1-norm error for hilb: 4.163336342344337e-17

Magic squares

All row sums, column sums and both diagonal sums of a magic square are equal:

M = matrixdepot("magic", Int, 5)
(rows = vec(sum(M, dims=2)), cols = vec(sum(M, dims=1)),
 diag = sum(diag(M)), antidiag = sum(diag(reverse(M, dims=2))))
(rows = [65, 65, 65, 65, 65], cols = [65, 65, 65, 65, 65], diag = 65, antidiag = 65)

Pascal matrices

The Cholesky factor of the Pascal matrix contains the rows of Pascal's triangle:

P = matrixdepot("pascal", Int, 6)
cholesky(P).U
6×6 LinearAlgebra.UpperTriangular{Float64, Matrix{Float64}}:
 1.0  1.0  1.0  1.0  1.0   1.0
  ⋅   1.0  2.0  3.0  4.0   5.0
  ⋅    ⋅   1.0  3.0  6.0  10.0
  ⋅    ⋅    ⋅   1.0  4.0  10.0
  ⋅    ⋅    ⋅    ⋅   1.0   5.0
  ⋅    ⋅    ⋅    ⋅    ⋅    1.0