@@ -2,6 +2,7 @@ using ApproxFunOrthogonalPolynomials
2
2
using ApproxFunBase
3
3
using ApproxFunBase: bandwidth
4
4
using BandedMatrices
5
+ using LinearAlgebra
5
6
using SpecialFunctions
6
7
using Test
7
8
@@ -11,28 +12,24 @@ using Test
11
12
# -𝒟² u = λu, u'(±1) = 0.
12
13
#
13
14
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
36
33
end
37
34
38
35
@testset " Schrödinger with piecewise-linear potential with Dirichlet boundary conditions" begin
@@ -42,25 +39,14 @@ using Test
42
39
# where V = 100|x|.
43
40
#
44
41
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)))
47
43
V = 100 Fun (abs, S)
48
44
L = - Derivative (S, 2 ) + V
49
- C = Conversion (domainspace (L), rangespace (L))
50
45
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
59
46
47
+ Seig = SymmetricEigensystem (L, B)
60
48
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)
64
50
65
51
@test λ[1 ] ≈ parse (BigFloat, " 2.19503852085715200848808942880214615154684642693583513254593767079468401198338e+01" )
66
52
end
@@ -71,26 +57,17 @@ using Test
71
57
#
72
58
# where V = 1000[χ_[-1,-1/2](x) + χ_[1/2,1](x)].
73
59
#
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
+
77
63
V = Fun (x-> abs (x) ≥ 1 / 2 ? 1000 : 0 , S)
78
64
L = - Derivative (S, 2 ) + V
79
- C = Conversion (domainspace (L), rangespace (L))
80
65
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)
89
68
90
69
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)
94
71
# From Lee--Greengard (1997).
95
72
λtrue = [2.95446 ;5.90736 ;8.85702 ;11.80147 ]. ^ 2
96
73
@test norm ((λ[1 : 4 ] - λtrue ). / λ[1 : 4 ]) < 1e-5
@@ -102,36 +79,27 @@ using Test
102
79
#
103
80
# where V = x + 100δ(x-0.25).
104
81
#
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)))
108
84
V = Fun (identity, S)
109
85
L = - Derivative (S, 2 ) + V
110
- C = Conversion ( domainspace (L), rangespace (L))
86
+
111
87
B4 = zeros (Operator{ApproxFunBase. prectype (S)}, 1 , 2 )
112
88
B4[1 , 1 ] = - Evaluation (component (S, 1 ), rightendpoint, 1 ) - 100 * 0.5 * Evaluation (component (S, 1 ), rightendpoint)
113
89
B4[1 , 2 ] = Evaluation (component (S, 2 ), leftendpoint, 1 ) - 100 * 0.5 * Evaluation (component (S, 2 ), leftendpoint)
114
90
B4 = ApproxFunBase. InterlaceOperator (B4, PiecewiseSpace, ApproxFunBase. ArraySpace)
115
91
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
124
92
125
93
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);
128
97
98
+ QS = QuotientSpace (B)
129
99
k = 3
130
-
131
- λ, Q = eigen (SA, SB);
132
100
u_QS = Fun (QS, Q[:, k])
133
101
u_S = Fun (u_QS, S)
134
- u = Fun (u_S, PiecewiseSpace (Chebyshev .(d . domains )))
102
+ u = Fun (u_S, PiecewiseSpace (Chebyshev .(components (d) )))
135
103
u /= sign (u' (- 1 ))
136
104
u1, u2 = components (u)
137
105
@@ -149,22 +117,13 @@ using Test
149
117
#
150
118
d = Segment (big (- 1.0 ).. big (1.0 ))
151
119
S = Ultraspherical (big (0.5 ), d)
152
- NS = NormalizedPolynomialSpace (S)
153
120
L = - Derivative (S, 2 )
154
121
C = Conversion (domainspace (L), rangespace (L))
155
122
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
164
123
165
124
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 )
168
127
BSA = BandedMatrix (SA)
169
128
BSB = BandedMatrix (SB)
170
129
begin
@@ -189,21 +148,13 @@ using Test
189
148
#
190
149
d = Segment (- 1 .. 1 )
191
150
S = Ultraspherical (0.5 , d)
192
- NS = NormalizedPolynomialSpace (S)
193
151
Lsk = Derivative (S)
194
- Csk = Conversion (domainspace (Lsk), rangespace (Lsk))
195
152
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)
204
154
205
155
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))
207
158
208
159
@test abs .(λim[1 : 2 : round (Int, 2 n/ 5 )]) ≈ π.* (0.5 : round (Int, 2 n/ 5 )/ 2 )
209
160
@test abs .(λim[2 : 2 : round (Int, 2 n/ 5 )]) ≈ π.* (0.5 : round (Int, 2 n/ 5 )/ 2 )
0 commit comments