@@ -2,6 +2,7 @@ using ApproxFunOrthogonalPolynomials
22using ApproxFunBase
33using ApproxFunBase: bandwidth
44using BandedMatrices
5+ using LinearAlgebra
56using SpecialFunctions
67using Test
78
@@ -11,28 +12,24 @@ using Test
1112 # -𝒟² u = λu, u'(±1) = 0.
1213 #
1314 d = Segment (- 1 .. 1 )
14- S = Ultraspherical (0.5 , d)
15- NS = NormalizedPolynomialSpace (S)
16- L = - Derivative (S, 2 )
17- C = Conversion (domainspace (L), rangespace (L))
18- B = Neumann (S)
19- QS = QuotientSpace (B)
20- Q = Conversion (QS, S)
21- D1 = Conversion (S, NS)
22- D2 = Conversion (NS, S)
23- R = D1* Q
24- P = cache (PartialInverseOperator (C, (0 , bandwidth (L, 1 ) + bandwidth (R, 1 ) + bandwidth (C, 2 ))))
25- A = R' D1* P* L* D2* R
26- B = R' R
27-
28- # Currently a hack to avoid a LAPACK calling bug with a pencil (A, B)
29- # with smaller bandwidth in A.
30- n = 50
31- SA = Symmetric (Matrix (A[1 : n,1 : n]), :L )
32- SB = Symmetric (Matrix (B[1 : n,1 : n]), :L )
33- λ = eigvals (SA, SB)
34-
35- @test λ[1 : round (Int, 2 n/ 5 )] ≈ (π^ 2 / 4 ). * (0 : round (Int, 2 n/ 5 )- 1 ). ^ 2
15+ for S in (Ultraspherical (0.5 , d), Legendre (d))
16+ L = - Derivative (S, 2 )
17+ B = Neumann (S)
18+
19+ n = 50
20+ Seig = SymmetricEigensystem (L, B)
21+ SA, SB = bandmatrices_eigen (Seig, n)
22+
23+ # A hack to avoid a BandedMatrices bug on Julia v1.6, with a pencil (A, B)
24+ # with smaller bandwidth in A.
25+ λ = if VERSION >= v " 1.8"
26+ eigvals (SA, SB)
27+ else
28+ eigvals (Symmetric (Matrix (SA)), Symmetric (Matrix (SB)))
29+ end
30+
31+ @test λ[1 : round (Int, 2 n/ 5 )] ≈ (π^ 2 / 4 ). * (0 : round (Int, 2 n/ 5 )- 1 ). ^ 2
32+ end
3633 end
3734
3835 @testset " Schrödinger with piecewise-linear potential with Dirichlet boundary conditions" begin
@@ -42,25 +39,14 @@ using Test
4239 # where V = 100|x|.
4340 #
4441 d = Segment (- 1 .. 0 )∪ Segment (0 .. 1 )
45- S = PiecewiseSpace (Ultraspherical .(0.5 , d. domains))
46- NS = PiecewiseSpace (NormalizedUltraspherical .(0.5 , d. domains))
42+ S = PiecewiseSpace (Ultraspherical .(0.5 , components (d)))
4743 V = 100 Fun (abs, S)
4844 L = - Derivative (S, 2 ) + V
49- C = Conversion (domainspace (L), rangespace (L))
5045 B = [Dirichlet (S); continuity (S, 0 : 1 )]
51- QS = QuotientSpace (B)
52- Q = Conversion (QS, S)
53- D1 = Conversion (S, NS)
54- D2 = Conversion (NS, S)
55- R = D1* Q
56- P = cache (PartialInverseOperator (C, (0 , bandwidth (L, 1 ) + bandwidth (R, 1 ) + bandwidth (C, 2 ))))
57- A = R' D1* P* L* D2* R
58- B = R' R
5946
47+ Seig = SymmetricEigensystem (L, B)
6048 n = 100
61- SA = Symmetric (A[1 : n,1 : n], :L )
62- SB = Symmetric (B[1 : n,1 : n], :L )
63- λ = eigvals (SA, SB)
49+ λ = eigvals (Seig, n)
6450
6551 @test λ[1 ] ≈ parse (BigFloat, " 2.19503852085715200848808942880214615154684642693583513254593767079468401198338e+01" )
6652 end
@@ -71,26 +57,17 @@ using Test
7157 #
7258 # where V = 1000[χ_[-1,-1/2](x) + χ_[1/2,1](x)].
7359 #
74- d = Segment (- 1 .. (- 0.5 ))∪ Segment (- 0.5 .. 0.5 )∪ Segment (0.5 .. 1 )
75- S = PiecewiseSpace (Ultraspherical .(0.5 , d . domains ))
76- NS = PiecewiseSpace ( NormalizedUltraspherical .( 0.5 , d . domains))
60+ d = Segment (- 1 .. (- 0.5 )) ∪ Segment (- 0.5 .. 0.5 ) ∪ Segment (0.5 .. 1 )
61+ S = PiecewiseSpace (Ultraspherical .(0.5 , components (d) ))
62+
7763 V = Fun (x-> abs (x) ≥ 1 / 2 ? 1000 : 0 , S)
7864 L = - Derivative (S, 2 ) + V
79- C = Conversion (domainspace (L), rangespace (L))
8065 B = [Dirichlet (S); continuity (S, 0 : 1 )]
81- QS = QuotientSpace (B)
82- Q = Conversion (QS, S)
83- D1 = Conversion (S, NS)
84- D2 = Conversion (NS, S)
85- R = D1* Q
86- P = cache (PartialInverseOperator (C, (0 , bandwidth (L, 1 ) + bandwidth (R, 1 ) + bandwidth (C, 2 ))))
87- A = R' D1* P* L* D2* R
88- B = R' R
66+
67+ Seig = SymmetricEigensystem (L, B)
8968
9069 n = 150
91- SA = Symmetric (A[1 : n,1 : n], :L )
92- SB = Symmetric (B[1 : n,1 : n], :L )
93- λ = eigvals (SA, SB)
70+ λ = eigvals (Seig, n)
9471 # From Lee--Greengard (1997).
9572 λtrue = [2.95446 ;5.90736 ;8.85702 ;11.80147 ]. ^ 2
9673 @test norm ((λ[1 : 4 ] - λtrue ). / λ[1 : 4 ]) < 1e-5
@@ -102,36 +79,27 @@ using Test
10279 #
10380 # where V = x + 100δ(x-0.25).
10481 #
105- d = Segment (- 1 .. 0.25 )∪ Segment (0.25 .. 1 )
106- S = PiecewiseSpace (Ultraspherical .(0.5 , d. domains))
107- NS = PiecewiseSpace (NormalizedUltraspherical .(0.5 , d. domains))
82+ d = Segment (- 1 .. 0.25 ) ∪ Segment (0.25 .. 1 )
83+ S = PiecewiseSpace (Ultraspherical .(0.5 , components (d)))
10884 V = Fun (identity, S)
10985 L = - Derivative (S, 2 ) + V
110- C = Conversion ( domainspace (L), rangespace (L))
86+
11187 B4 = zeros (Operator{ApproxFunBase. prectype (S)}, 1 , 2 )
11288 B4[1 , 1 ] = - Evaluation (component (S, 1 ), rightendpoint, 1 ) - 100 * 0.5 * Evaluation (component (S, 1 ), rightendpoint)
11389 B4[1 , 2 ] = Evaluation (component (S, 2 ), leftendpoint, 1 ) - 100 * 0.5 * Evaluation (component (S, 2 ), leftendpoint)
11490 B4 = ApproxFunBase. InterlaceOperator (B4, PiecewiseSpace, ApproxFunBase. ArraySpace)
11591 B = [Evaluation (S, - 1 ); Evaluation (S, 1 ) + Evaluation (S, 1 , 1 ); continuity (S, 0 ); B4]
116- QS = QuotientSpace (B)
117- Q = Conversion (QS, S)
118- D1 = Conversion (S, NS)
119- D2 = Conversion (NS, S)
120- R = D1* Q
121- P = cache (PartialInverseOperator (C, (0 , bandwidth (L, 1 ) + bandwidth (R, 1 ) + bandwidth (C, 2 ))))
122- A = R' D1* P* L* D2* R
123- B = R' R
12492
12593 n = 100
126- SA = Symmetric (A[1 : n,1 : n], :L )
127- SB = Symmetric (B[1 : n,1 : n], :L )
94+ Seig = SymmetricEigensystem (L, B)
95+ SA, SB = bandmatrices_eigen (Seig, n)
96+ λ, Q = eigen (SA, SB);
12897
98+ QS = QuotientSpace (B)
12999 k = 3
130-
131- λ, Q = eigen (SA, SB);
132100 u_QS = Fun (QS, Q[:, k])
133101 u_S = Fun (u_QS, S)
134- u = Fun (u_S, PiecewiseSpace (Chebyshev .(d . domains )))
102+ u = Fun (u_S, PiecewiseSpace (Chebyshev .(components (d) )))
135103 u /= sign (u' (- 1 ))
136104 u1, u2 = components (u)
137105
@@ -149,22 +117,13 @@ using Test
149117 #
150118 d = Segment (big (- 1.0 ).. big (1.0 ))
151119 S = Ultraspherical (big (0.5 ), d)
152- NS = NormalizedPolynomialSpace (S)
153120 L = - Derivative (S, 2 )
154121 C = Conversion (domainspace (L), rangespace (L))
155122 B = Dirichlet (S)
156- QS = QuotientSpace (B)
157- Q = Conversion (QS, S)
158- D1 = Conversion (S, NS)
159- D2 = Conversion (NS, S)
160- R = D1* Q
161- P = cache (PartialInverseOperator (C, (0 , bandwidth (L, 1 ) + bandwidth (R, 1 ) + bandwidth (C, 2 ))))
162- A = R' D1* P* L* D2* R
163- B = R' R
164123
165124 n = 300
166- SA = Symmetric (A[ 1 : n, 1 : n], :L )
167- SB = Symmetric (B[ 1 : n, 1 : n], :L )
125+ Seig = SymmetricEigensystem (L, B )
126+ SA, SB = bandmatrices_eigen (Seig, n )
168127 BSA = BandedMatrix (SA)
169128 BSB = BandedMatrix (SB)
170129 begin
@@ -189,21 +148,13 @@ using Test
189148 #
190149 d = Segment (- 1 .. 1 )
191150 S = Ultraspherical (0.5 , d)
192- NS = NormalizedPolynomialSpace (S)
193151 Lsk = Derivative (S)
194- Csk = Conversion (domainspace (Lsk), rangespace (Lsk))
195152 B = Evaluation (S, - 1 ) + Evaluation (S, 1 )
196- QS = PathologicalQuotientSpace (B)
197- Q = Conversion (QS, S)
198- D1 = Conversion (S, NS)
199- D2 = Conversion (NS, S)
200- R = D1* Q
201- Psk = cache (PartialInverseOperator (Csk, (0 , 4 + bandwidth (Lsk, 1 ) + bandwidth (R, 1 ) + bandwidth (Csk, 2 ))))
202- Ask = R' D1* Psk* Lsk* D2* R
203- Bsk = R' R
153+ Seig = SkewSymmetricEigensystem (Lsk, B, PathologicalQuotientSpace)
204154
205155 n = 100
206- λim = imag (sort! (eigvals (Matrix (tril (Ask[1 : n,1 : n], 1 )), Matrix (tril (Bsk[1 : n,1 : n], 2 ))), by = abs))
156+ λ = eigvals (Seig, n)
157+ λim = imag (sort! (λ, by = abs))
207158
208159 @test abs .(λim[1 : 2 : round (Int, 2 n/ 5 )]) ≈ π.* (0.5 : round (Int, 2 n/ 5 )/ 2 )
209160 @test abs .(λim[2 : 2 : round (Int, 2 n/ 5 )]) ≈ π.* (0.5 : round (Int, 2 n/ 5 )/ 2 )
0 commit comments