1
+ using Test, ClassicalOrthogonalPolynomials, BandedMatrices, LinearAlgebra, LazyArrays, ContinuumArrays, LazyBandedMatrices
2
+ import ClassicalOrthogonalPolynomials: symmjacobim
3
+
4
+ @testset begin " Test the Q&D conversion to BandedMatrix format"
5
+ # Legendre
6
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
7
+ x = axes (P,1 )
8
+ J = jacobimatrix (P)
9
+ Jx = symmjacobim (J)
10
+ @test J[1 : 100 ,1 : 100 ] == Jx[1 : 100 ,1 : 100 ]
11
+ # Jacobi
12
+ P = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
13
+ x = axes (P,1 )
14
+ J = jacobimatrix (P)
15
+ Jx = symmjacobim (J)
16
+ @test J[1 : 100 ,1 : 100 ] == Jx[1 : 100 ,1 : 100 ]
17
+ end
18
+
19
+ @testset begin " Basic properties of Cholesky based Jacobi operators"
20
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
21
+ x = axes (P,1 )
22
+ J = jacobimatrix (P)
23
+ Jx = symmjacobim (J)
24
+ w = (I - Jx^ 2 )
25
+ # banded cholesky for symmetric-tagged W
26
+ @test cholesky (w). U isa UpperTriangular
27
+ # compute Jacobi matrix via cholesky
28
+ Jchol = cholesky_jacobimatrix (w)
29
+ @test Jchol isa LazyBandedMatrices. SymTridiagonal
30
+ end
31
+
32
+ @testset begin " Comparison with Lanczos and Classical for w(x) = x^2*(1-x)"
33
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
34
+ x = axes (P,1 )
35
+ J = jacobimatrix (P)
36
+ Jx = symmjacobim (J)
37
+ w = (Jx^ 2 - Jx^ 3 )
38
+ # compute Jacobi matrix via cholesky
39
+ Jchol = cholesky_jacobimatrix (w)
40
+ # compute Jacobi matrix via classical recurrence
41
+ Q = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
42
+ Jclass = jacobimatrix (Q)
43
+ # compute Jacobi matrix via Lanczos
44
+ wf = x.^ 2 .* (1 .- x)
45
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
46
+ # Comparison with Lanczos
47
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
48
+ # Comparison with Classical
49
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jclass[1 : 500 ,1 : 500 ]
50
+ end
51
+
52
+ @testset begin " Comparison with Lanczos for w(x) = (1-x^2)"
53
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
54
+ x = axes (P,1 )
55
+ J = jacobimatrix (P)
56
+ Jx = symmjacobim (J)
57
+ w = (I - Jx^ 2 )
58
+ # compute Jacobi matrix via cholesky
59
+ Jchol = cholesky_jacobimatrix (w)
60
+ # compute Jacobi matrix via Lanczos
61
+ wf = (1 .- x.^ 2 )
62
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
63
+ # Comparison
64
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
65
+ end
66
+
67
+ @testset begin " Comparison with Lanczos for w(x) = (1-x^4)"
68
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
69
+ x = axes (P,1 )
70
+ J = jacobimatrix (P)
71
+ Jx = symmjacobim (J)
72
+ w = (I - Jx^ 4 )
73
+ # compute Jacobi matrix via cholesky
74
+ Jchol = cholesky_jacobimatrix (w)
75
+ # compute Jacobi matrix via Lanczos
76
+ wf = (1 .- x.^ 4 )
77
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
78
+ # Comparison
79
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
80
+ end
81
+
82
+ @testset begin " Comparison with Lanczos for w(x) = (1.014-x^3)"
83
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
84
+ x = axes (P,1 )
85
+ J = jacobimatrix (P)
86
+ Jx = symmjacobim (J)
87
+ t = 1.014
88
+ w = (t* I - Jx^ 3 )
89
+ # compute Jacobi matrix via cholesky
90
+ Jchol = cholesky_jacobimatrix (w)
91
+ # compute Jacobi matrix via Lanczos
92
+ wf = (t .- x.^ 3 )
93
+ Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
94
+ # Comparison
95
+ @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
96
+ end
0 commit comments