Getting Started

Installation

TypedMatrices.jl is registered in the Julia package registry, and Julia's builtin package manager can be used to install it:

pkg> add TypedMatrices

Setup

The first step is, as usual, to load the package:

julia> using TypedMatrices

The list of available matrices can be obtained with list_matrices:

julia> matrix_list = list_matrices()63-element Vector{Type{<:AbstractMatrix}}:
 Hilbert
 Pei
 Wathen
 Moler
 Golub
 Rohess
 Redheff
 Toeplitz
 Chow
 Cycol
 ⋮
 Ipjfact
 Lehmer
 Companion
 InverseHilbert
 Riemann
 Dramadah
 RIS
 Randjorth
 Smoke

The function returns a Vector of matrix types, which are subtypes of AbstractMatrix. The elements of this Vector can be used to generate matrices:

julia> matrix_list[1](4)4×4 Hilbert{Rational{Int64}}:
  1    1//2  1//3  1//4
 1//2  1//3  1//4  1//5
 1//3  1//4  1//5  1//6
 1//4  1//5  1//6  1//7

Generating Matrices

Each type of special matrices has its own type and constructors. For example, a 5 × 5 Hilbert matrix can be generated with:

julia> h = Hilbert(5)5×5 Hilbert{Rational{Int64}}:
  1    1//2  1//3  1//4  1//5
 1//2  1//3  1//4  1//5  1//6
 1//3  1//4  1//5  1//6  1//7
 1//4  1//5  1//6  1//7  1//8
 1//5  1//6  1//7  1//8  1//9

Most matrices can accept a type parameter to specify the element type. For example, a 5 × 5 Hilbert matrix with Float64 elements can be generated with:

julia> Hilbert{Float64}(5)5×5 Hilbert{Float64}:
 1.0       0.5       0.333333  0.25      0.2
 0.5       0.333333  0.25      0.2       0.166667
 0.333333  0.25      0.2       0.166667  0.142857
 0.25      0.2       0.166667  0.142857  0.125
 0.2       0.166667  0.142857  0.125     0.111111

Please check the list of Builtin Matrices for an overview of all available types.

Properties

Matrices have properties such as "symmetric", "ill conditioned", or "positive definite".

The function list_properties can be used to show all properties currently defined in TypedMatrices.jl:

julia> list_properties()37-element Vector{Property}:
 Property(:positive)
 Property(:correlation)
 Property(:random)
 Property(:regprob)
 Property(:sparse)
 Property(:totnonneg)
 Property(:inverse)
 Property(:nilpotent)
 Property(:indefinite)
 Property(:tridiagonal)
 ⋮
 Property(:normal)
 Property(:rectangular)
 Property(:posdef)
 Property(:diagdom)
 Property(:eigen)
 Property(:hessenberg)
 Property(:unimodular)
 Property(:singval)
 Property(:toeplitz)

The function properties can used to get the properties of a given matrix type:

julia> properties(Hilbert)6-element Vector{Property}:
 Property(:symmetric)
 Property(:inverse)
 Property(:hankel)
 Property(:illcond)
 Property(:posdef)
 Property(:totpos)

For convenience, the same function can be used to list the properties of a matrix instance, rather than a type:

julia> properties(h)6-element Vector{Property}:
 Property(:symmetric)
 Property(:inverse)
 Property(:hankel)
 Property(:illcond)
 Property(:posdef)
 Property(:totpos)

Grouping

Matrices can be organized by creating user-defined groups. All builtin matrices belong to the :builtin group, and the package comes with an empty :user group for user-defined matrices. All available groups can be listed with:

julia> list_groups()2-element Vector{Group}:
 Group(:user)
 Group(:builtin)

The function add_to_groups can be used to add a matrix to a group:

julia> add_to_groups(Matrix, :user, :test)

The function list_matrices can be used to list the matrices that belong to a chosen group:

julia> list_matrices(Group(:user))1-element Vector{Type{<:AbstractMatrix}}:
 Matrix (alias for Array{T, 2} where T)

Builtin matrices can also be added to a group:

julia> add_to_groups(Hilbert, :test)
julia> list_matrices(Group(:test))2-element Vector{Type{<:AbstractMatrix}}: Matrix (alias for Array{T, 2} where T) Hilbert

A matrix can be removed:

Matrices cannot be removed from the :builtin group, and user-defined groups are automatically removed when they become empty:

julia> remove_from_group(Hilbert, :test)
julia> remove_from_all_groups(Matrix)
julia> list_groups()2-element Vector{Group}: Group(:user) Group(:builtin)

Finding Matrices

list_matrices is a powerful function to search for matrices, and filter the results by groups or properties. All arguments are "and" relationship, meaning that only matrices that satisfy all conditions will be retained.

For example, one can list all the matrices in the :builtin group, or all those that are satisfy the :symmetric property:

julia> list_matrices(Group(:builtin))63-element Vector{Type{<:AbstractMatrix}}:
 Hilbert
 Pei
 Wathen
 Moler
 Golub
 Rohess
 Redheff
 Toeplitz
 Chow
 Cycol
 ⋮
 Ipjfact
 Lehmer
 Companion
 InverseHilbert
 Riemann
 Dramadah
 RIS
 Randjorth
 Smoke
julia> list_matrices(Property(:symmetric))21-element Vector{Type{<:AbstractMatrix}}: Hilbert Pei Wathen Moler Minij Cauchy Pascal Rosser Poisson Wilkinson ⋮ KMS Hankel Prolate GCDMat Randcorr Ipjfact Lehmer InverseHilbert RIS

One can also combine the two filters and show all matrices in the :builtin group that satisfy the :inverse, :illcond, and :eigen properties:

julia> list_matrices(
           [
               Group(:builtin),
           ],
           [
               Property(:inverse),
               Property(:illcond),
               Property(:eigen),
           ]
       )3-element Vector{Type{<:AbstractMatrix}}:
 Pascal
 Forsythe
 Lotkin

A simpler syntax can be used to list all matrices that satisfy a list of properties. For example, all matrices with :symmetric, :eigen, and :posdef can be listed with:

julia> list_matrices(:symmetric, :eigen, :posdef)4-element Vector{Type{<:AbstractMatrix}}:
 Wathen
 Minij
 Pascal
 Poisson

The list_matrices functions provides a number of alternative interfaces. Check the full documentation of list_matrices or use the Julia help system for a complete list.