|
| 1 | +""" |
| 2 | +MIN[I,J] Matrix |
| 3 | +=============== |
| 4 | +A matrix with `(i,j)` entry `min(i,j)`. It is a symmetric positive |
| 5 | + definite matrix. The eigenvalues and eigenvectors are known |
| 6 | + explicitly. Its inverse is tridiagonal. |
| 7 | +
|
| 8 | +*Input options:* |
| 9 | +
|
| 10 | ++ [type,] dim: the dimension of the matrix. |
| 11 | +
|
| 12 | +*Groups:* ["inverse", "symmetric", "posdef", "eigen"] |
| 13 | +
|
| 14 | +*References:* |
| 15 | +
|
| 16 | +**J. Fortiana and C. M. Cuadras**, A family of matrices, |
| 17 | + the discretized Brownian bridge, and distance-based regression, |
| 18 | + Linear Algebra Appl., 264 (1997), 173-188. (For the eigensystem of A.) |
| 19 | +""" |
| 20 | +struct Minij{T<:Integer} <: AbstractMatrix{T} |
| 21 | + n::Int |
| 22 | + |
| 23 | + function Minij(::Type{T}, n::Int) where {T<:Integer} |
| 24 | + n > 0 || throw(ArgumentError("$n ≤ 0")) |
| 25 | + return new{T}(n) |
| 26 | + end |
| 27 | +end |
| 28 | + |
| 29 | +# constructors |
| 30 | +Minij(n::Int) = Minij(Int, n) |
| 31 | + |
| 32 | +# metadata |
| 33 | +@properties Minij [:symmetric, :inverse, :posdef, :eigen] |
| 34 | + |
| 35 | +# properties |
| 36 | +size(s::Minij) = (s.n, s.n) |
| 37 | +LinearAlgebra.isdiag(::Minij) = false |
| 38 | +LinearAlgebra.ishermitian(::Minij) = true |
| 39 | +LinearAlgebra.isposdef(::Minij) = true |
| 40 | +LinearAlgebra.issymmetric(::Minij) = true |
| 41 | +LinearAlgebra.adjoint(A::Minij) = A |
| 42 | +LinearAlgebra.transpose(A::Minij) = A |
| 43 | + |
| 44 | +# functions |
| 45 | +@inline Base.Base.@propagate_inbounds function getindex(A::Minij{T}, i::Integer, j::Integer) where {T} |
| 46 | + @boundscheck checkbounds(A, i, j) |
| 47 | + return T(min(i, j)) |
| 48 | +end |
| 49 | + |
| 50 | +function LinearAlgebra.inv(A::Minij{T}) where {T} |
| 51 | + if A.n == 1 |
| 52 | + return ones(T, 1, 1) |
| 53 | + else |
| 54 | + return SymTridiagonal(2 * ones(T, A.n), -ones(T, A.n - 1)) |
| 55 | + end |
| 56 | +end |
0 commit comments