1
1
using Test, ClassicalOrthogonalPolynomials, BandedMatrices, LinearAlgebra, LazyArrays, ContinuumArrays, LazyBandedMatrices
2
2
import ClassicalOrthogonalPolynomials: symmjacobim, CholeskyJacobiBands
3
3
import LazyArrays: AbstractCachedMatrix
4
+ import LazyBandedMatrices: SymTridiagonal
4
5
5
6
@testset " Basic properties" begin
6
7
@testset " Test the Q&D conversion to BandedMatrix format" begin
@@ -35,12 +36,11 @@ import LazyArrays: AbstractCachedMatrix
35
36
Cbands = CholeskyJacobiBands (w)
36
37
@test Cbands isa CholeskyJacobiBands
37
38
@test Cbands isa AbstractCachedMatrix
38
- @test Cbands[1 ,100 ] == (Cbands[1 ,1 : 100 ])[100 ]
39
- @test Cbands[:,50 ] == [Cbands[1 ,50 ],Cbands[2 ,50 ]]
39
+ @test getindex (Cbands,1 ,100 ) == getindex (Cbands,1 ,1 : 100 )[100 ]
40
40
end
41
41
end
42
42
43
- @testset " Comparison with Lanczos and Classical" begin
43
+ @testset " Comparison with Lanczos and Classical, non-Clenshaw " begin
44
44
@testset " w(x) = x^2*(1-x)" begin
45
45
P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
46
46
x = axes (P,1 )
106
106
# Comparison
107
107
@test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
108
108
end
109
+ end
110
+
111
+ @testset " Comparison with Lanczos and Classical, with Clenshaw, basics" begin
112
+ @testset " w(x) = x^2*(1-x)" begin
113
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
114
+ x = axes (P,1 )
115
+ J = jacobimatrix (P)
116
+ Jx = symmjacobim (J)
117
+ wf (x) = x^ 2 * (1 - x)
118
+ # compute Jacobi matrix via cholesky
119
+ W = P \ (wf .(x) .* P)
120
+ Jchol = cholesky_jacobimatrix (Symmetric (W))
121
+ # compute Jacobi matrix via classical recurrence
122
+ Q = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
123
+ Jclass = jacobimatrix (Q)
124
+ # compute Jacobi matrix via Lanczos
125
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
126
+ # Comparison with Lanczos
127
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
128
+ # Comparison with Classical
129
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jclass[1 : 500 ,1 : 500 ]
130
+ end
131
+
132
+ @testset " w(x) = (1-x^2)" begin
133
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
134
+ x = axes (P,1 )
135
+ J = jacobimatrix (P)
136
+ Jx = symmjacobim (J)
137
+ wf (x) = (1 - x^ 2 )
138
+ # compute Jacobi matrix via cholesky
139
+ W = P \ (wf .(x) .* P)
140
+ Jchol = cholesky_jacobimatrix (Symmetric (W))
141
+ # compute Jacobi matrix via Lanczos
142
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
143
+ # Comparison with Lanczos
144
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
145
+ end
146
+
147
+ @testset " w(x) = (1-x^4)" begin
148
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
149
+ x = axes (P,1 )
150
+ J = jacobimatrix (P)
151
+ Jx = symmjacobim (J)
152
+ wf (x) = (1 - x^ 4 )
153
+ # compute Jacobi matrix via cholesky
154
+ W = P \ (wf .(x) .* P)
155
+ Jchol = cholesky_jacobimatrix (Symmetric (W))
156
+ # compute Jacobi matrix via Lanczos
157
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
158
+ # Comparison with Lanczos
159
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
160
+ end
161
+
162
+ @testset " w(x) = (1.014-x^3)" begin
163
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
164
+ x = axes (P,1 )
165
+ J = jacobimatrix (P)
166
+ Jx = symmjacobim (J)
167
+ wf (x) = 1.014 - x^ 4
168
+ # compute Jacobi matrix via cholesky
169
+ W = P \ (wf .(x) .* P)
170
+ Jchol = cholesky_jacobimatrix (Symmetric (W))
171
+ # compute Jacobi matrix via Lanczos
172
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
173
+ # Comparison with Lanczos
174
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
175
+ end
109
176
end
0 commit comments