Skip to content

Commit e388304

Browse files
committed
feat(matrices): add clement
1 parent 779d04c commit e388304

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/matrices/clement.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Clement Matrix
3+
==============
4+
The Clement matrix is a tridiagonal matrix with zero
5+
diagonal entries. If k = 1, the matrix is symmetric.
6+
7+
*Input options:*
8+
9+
+ dim, k: `dim` is the dimension of the matrix.
10+
If `k = 0`, the matrix is of type `Tridiagonal`.
11+
If `k = 1`, the matrix is of type `SymTridiagonal`.
12+
13+
+ dim: `k = 0`.
14+
15+
*References:*
16+
17+
**P. A. Clement**, A class of triple-diagonal
18+
matrices for test purposes, SIAM Review, 1 (1959), pp. 50-52.
19+
"""
20+
abstract type Clement{T<:Number} <: AbstractMatrix{T} end
21+
22+
# constructors
23+
Clement(n::Integer) = Clement(n, 0)
24+
Clement(n::Integer, k::Integer) = Clement{Float64}(n, k)
25+
Clement{T}(n::Integer) where {T<:Number} = Clement{T}(n, 0)
26+
function Clement{T}(n::Integer, k::Integer) where {T}
27+
# 1x1 case
28+
if n == 1
29+
return zeros(T, 1, 1)
30+
end
31+
32+
# create the matrix
33+
n = n - 1
34+
x = T[n:-1:1;]
35+
z = T[1:n;]
36+
if k == 0
37+
return Tridiagonal(x, zeros(T, n + 1), z)
38+
else
39+
y = sqrt.(x .* z)
40+
return SymTridiagonal(zeros(T, n + 1), y)
41+
end
42+
end
43+
44+
# metadata
45+
@properties Clement [:symmetric, :inverse, :eigen]

src/matrices/index.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export
99
ChebSpec,
1010
Chow,
1111
Circulant,
12+
Clement,
1213
Companion,
1314
DingDong,
1415
Fiedler,
@@ -53,6 +54,7 @@ include("cauchy.jl")
5354
include("chebspec.jl")
5455
include("chow.jl")
5556
include("circulant.jl")
57+
include("clement.jl")
5658
include("companion.jl")
5759
include("dingdong.jl")
5860
include("fiedler.jl")
@@ -102,6 +104,7 @@ MATRIX_GROUPS[GROUP_BUILTIN] = Set([
102104
ChebSpec,
103105
Chow,
104106
Circulant,
107+
Clement,
105108
Companion,
106109
DingDong,
107110
Fiedler,

0 commit comments

Comments
 (0)