Skip to content

Commit 53f7010

Browse files
committed
Add normalized hermite eigevalue equation
1 parent 39f2f90 commit 53f7010

File tree

3 files changed

+78
-17
lines changed

3 files changed

+78
-17
lines changed

src/hermite.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ function getindex(w::HermiteWeight, x::Number)
77
exp(-x^2)
88
end
99

10+
sum(::HermiteWeight{T}) where T = sqrt(convert(T, π))
1011

1112
struct Hermite{T} <: OrthogonalPolynomial{T} end
1213
Hermite() = Hermite{Float64}()
14+
orthogonalityweight(::Hermite{T}) where T = HermiteWeight{T}()
1315

1416
==(::Hermite, ::Hermite) = true
1517
axes(::Hermite{T}) where T = (Inclusion(ℝ), oneto(∞))
@@ -33,4 +35,9 @@ end
3335
T = promote_type(eltype(D),eltype(H))
3436
D = _BandedMatrix((zero(T):2:∞)', ℵ₀, -1,1)
3537
H*D
38+
end
39+
40+
@simplify function *(D::Derivative, Q::OrthonormalWeighted{<:Any,<:Hermite})
41+
X = jacobimatrix(Q.P)
42+
Q * Tridiagonal(-X.ev, X.dv, X.ev)
3643
end

src/normalized.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ end
4747
normalizationconstant(P) = NormalizationConstant(P)
4848
Normalized(P::AbstractQuasiMatrix{T}) where T = Normalized(P, normalizationconstant(P))
4949
Normalized(Q::Normalized) = Q
50-
50+
normalized(P) = Normalized(P)
5151

5252
struct NormalizedBasisLayout{LAY<:AbstractBasisLayout} <: AbstractBasisLayout end
5353

@@ -166,3 +166,33 @@ end
166166
Base.array_summary(io::IO, C::NormalizationConstant{T}, inds) where T = print(io, "NormalizationConstant{$T}")
167167
show(io::IO, Q::Normalized) = print(io, "Normalized($(Q.P))")
168168
show(io::IO, ::MIME"text/plain", Q::Normalized) = show(io, Q)
169+
170+
171+
172+
struct OrthonormalWeighted{T, PP<:AbstractQuasiMatrix{T}} <: Basis{T}
173+
P::Normalized{T, PP, NormalizationConstant{T, PP}}
174+
end
175+
176+
function OrthonormalWeighted(P)
177+
Q = normalized(P)
178+
OrthonormalWeighted{eltype(Q),typeof(P)}(Q)
179+
end
180+
181+
axes(Q::OrthonormalWeighted) = axes(Q.P)
182+
copy(Q::OrthonormalWeighted) = Q
183+
184+
==(A::OrthonormalWeighted, B::OrthonormalWeighted) = A.P == B.P
185+
186+
function getindex(Q::OrthonormalWeighted, x::Number, jr::OneTo)
187+
w = orthogonalityweight(Q.P)
188+
sqrt(w[x]/sum(w)) * Q.P[x,jr]
189+
end
190+
191+
function getindex(Q::OrthonormalWeighted, x::Number, j::Number)
192+
w = orthogonalityweight(Q.P)
193+
sqrt(w[x]) * Q.P[x,j]
194+
end
195+
196+
getindex(Q::OrthonormalWeighted, x::Number, n::AbstractVector) = Q[x, Base.OneTo(maximum(n))][n]
197+
198+
broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::OrthonormalWeighted) = Q * (Q.P \ (x .* Q.P))

test/test_hermite.jl

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
using ClassicalOrthogonalPolynomials, ContinuumArrays, FillArrays, Test
2-
import ClassicalOrthogonalPolynomials: jacobimatrix, oneto
2+
import ClassicalOrthogonalPolynomials: jacobimatrix, oneto, OrthonormalWeighted
33
import DomainSets:
44

5-
@testset "Hermite" begin
6-
H = Hermite()
7-
w = HermiteWeight()
8-
9-
@test axes(H) == (Inclusion(ℝ), oneto(∞))
10-
x = axes(H,1)
11-
@test H[0.1,1:4] [1,2*0.1,4*0.1^2-2,8*0.1^3-12*0.1]
12-
@test w[0.1] exp(-0.1^2)
5+
@testset "Hermite" begin
6+
@testset "Basics" begin
7+
H = Hermite()
8+
w = HermiteWeight()
9+
@test axes(H) == (Inclusion(ℝ), oneto(∞))
10+
x = axes(H,1)
11+
@test H[0.1,1:4] [1,2*0.1,4*0.1^2-2,8*0.1^3-12*0.1]
12+
@test w[0.1] exp(-0.1^2)
1313

14-
X = jacobimatrix(H)
15-
@test 0.1 * H[0.1,1:10]' H[0.1,1:11]'*X[1:11,1:10]
14+
X = jacobimatrix(H)
15+
@test 0.1 * H[0.1,1:10]' H[0.1,1:11]'*X[1:11,1:10]
1616

17-
@test (H'*(w .* H))[1,1] sqrt(π)
18-
@test (H'*(w .* H))[2,2] 2sqrt(π)
19-
@test (H'*(w .* H))[3,3] 8sqrt(π)
17+
@test (H'*(w .* H))[1,1] sqrt(π)
18+
@test (H'*(w .* H))[2,2] 2sqrt(π)
19+
@test (H'*(w .* H))[3,3] 8sqrt(π)
2020

21-
D = Derivative(x)
22-
@test (D*H)[0.1,1:4] [0,2,8*0.1,24*0.1^2-12]
21+
D = Derivative(x)
22+
@test (D*H)[0.1,1:4] [0,2,8*0.1,24*0.1^2-12]
23+
end
24+
25+
@testset "OrthonormalWeighted" begin
26+
H = Hermite()
27+
Q = OrthonormalWeighted(H)
28+
@testset "evaluation" begin
29+
x = 0.1
30+
@test Q[x,1] exp(-x^2/2)/π^(1/4)
31+
@test Q[x,2] 2x*exp(-x^2/2)/(sqrt(2^(1/4))
32+
# Trap test of L^2 orthonormality
33+
x = range(-20,20; length=1_000)
34+
@test Q[x,1:5]'Q[x,1:5] * step(x) I
35+
end
36+
37+
@testset "Differentiation" begin
38+
x = axes(Q,1)
39+
D = Derivative(x)
40+
= Q \ (D * Q)
41+
@test D¹[1:10,1:10] -D¹[1:10,1:10]'
42+
= Q \ (D^2 * Q)
43+
X = Q \ (x .* Q)
44+
@test (D² - X^2)[1:10,1:10] -Diagonal(1:2:19)
45+
end
46+
end
2347
end

0 commit comments

Comments
 (0)