Skip to content

Commit 740a721

Browse files
authored
Add weighted Hermite Derivative (#125)
* Add weighted Hermite Derivative * add Quartic example
1 parent 3520770 commit 740a721

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.7.3"
4+
version = "0.7.4"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

examples/quarticev.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using ClassicalOrthogonalPolynomials
2+
import ClassicalOrthogonalPolynomials: OrthonormalWeighted
3+
4+
# find the 1m eigenvalue of -u'' + x^4*u
5+
6+
H = Hermite()
7+
Q = OrthonormalWeighted(H)
8+
x = axes(H,1)
9+
X = Q'*(x.*Q)
10+
D = Derivative(x)
11+
Δ = Q'*(D^2*Q)
12+
13+
L = -Δ + X^4
14+
15+
n = 1_000_000
16+
Lₙ = L[1:n,1:n]
17+
Fₙ = factorize(Symmetric(Lₙ));
18+
19+
v = [1; zeros(n-1)];
20+
21+
# find the smallest eigenvalue with inverse iteration
22+
for _=1:10
23+
w = Fₙ \ v; v = w/norm(w); v
24+
end
25+
λ = v'*Lₙ*v
26+
27+
@test λ eigvals(Symmetric(L[1:100,1:100]))[1]
28+
29+
# we can acellerate using Rayleigh shifts
30+
31+
v = [1; zeros(n-1)];
32+
33+
# find the millionth eigenvalue with inverse iteration
34+
n = 50_000_000
35+
E = 218506784;
36+
Lₙ = (L-E*I)[1:n,1:n]
37+
38+
Fₙ = factorize(Symmetric(Lₙ));
39+
40+
v = randn(n)
41+
42+
43+
for _=1:10
44+
w = Fₙ \ v; v = w/norm(w); v
45+
@show λ = v'*Lₙ*v
46+
end
47+
48+
49+
50+

src/classical/hermite.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ massmatrix(::Hermite{T}) where T = Diagonal(sqrt(convert(T,π)) .* convert(T,2)
5151
H*D
5252
end
5353

54+
@simplify function *(D::Derivative, W::Weighted{<:Any,<:Hermite})
55+
T = promote_type(eltype(D),eltype(W))
56+
D = _BandedMatrix(Fill(-one(T), 1, ∞), ℵ₀, 1,-1)
57+
W*D
58+
end
59+
5460
@simplify function *(D::Derivative, Q::OrthonormalWeighted{<:Any,<:Hermite})
5561
X = jacobimatrix(Q.P)
5662
Q * Tridiagonal(-X.ev, X.dv, X.ev)

src/normalized.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ weight(Q::OrthonormalWeighted) = sqrt.(orthogonalityweight(Q.P))
218218

219219
broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), x::Inclusion, Q::OrthonormalWeighted) = Q * (Q.P \ (x .* Q.P))
220220

221+
@simplify function *(Ac::QuasiAdjoint{<:Any,<:OrthonormalWeighted}, B::OrthonormalWeighted)
222+
@assert parent(Ac).P == B.P
223+
Eye{promote_type(eltype(Ac),eltype(B))}(∞)
224+
end
225+
221226

222227

223228
"""

test/test_hermite.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,20 @@ import DomainSets: ℝ
2222
@test (D*H)[0.1,1:4] [0,2,8*0.1,24*0.1^2-12]
2323
end
2424

25+
@testset "Weighted" begin
26+
H = Hermite()
27+
W = Weighted(H)
28+
x = axes(W,1)
29+
D = Derivative(x)
30+
@test (D*W)[0.1,1:4] [-2*0.1, 2-4*0.1^2, 12*0.1 - 8*0.1^3, -4*(3 - 12*0.1^2 + 4*0.1^4)]*exp(-0.1^2)
31+
end
32+
2533
@testset "OrthonormalWeighted" begin
2634
H = Hermite()
2735
Q = OrthonormalWeighted(H)
36+
37+
@test Q'Q == Eye(∞)
38+
2839
@testset "evaluation" begin
2940
x = 0.1
3041
@test Q[x,1] exp(-x^2/2)/π^(1/4)

0 commit comments

Comments
 (0)