Skip to content

Commit bd1af79

Browse files
authored
HalfWeighted derivatives (#36)
* Support HalfWeighted Derivatives * Half weighted a derivative * Half derivative b * c half derivative * Update test_derivative.jl
1 parent b574511 commit bd1af79

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

src/derivatives.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,55 @@ end
4444
Q = wQ.P
4545
P = SemiclassicalJacobi(Q.t, Q.a-1,Q.b-1,Q.c-1)
4646
Weighted(P) * ((-sum(orthogonalityweight(Q))/sum(orthogonalityweight(P))) * (Q \ (D * P))')
47+
end
48+
49+
@simplify function *(D::Derivative, HP::HalfWeighted{:a,<:Any,<:SemiclassicalJacobi})
50+
P = HP.P
51+
Q = SemiclassicalJacobi(P.t, P.a-1, P.b+1, P.c+1)
52+
a = Q.a
53+
A,B,C = recurrencecoefficients(P)
54+
α,β,γ = recurrencecoefficients(Q)
55+
d = AccumulateAbstractVector(*, A ./ α)
56+
v1 = MulAddAccumulate(Vcat(0,0,α[2:∞] ./ α), Vcat(0,β))
57+
v2 = MulAddAccumulate(Vcat(0,0,A[2:∞] ./ α), Vcat(0,B[1], B[2:end] .* d))
58+
59+
HalfWeighted{:a}(Q) * _BandedMatrix(
60+
Vcat(
61+
((a:∞) .* v2 .- ((a+1):∞) .* Vcat(1,v1[2:end] .* d))',
62+
(((a+1):∞) .* Vcat(1,d))'), ℵ₀, 0,1)
63+
end
64+
65+
@simplify function *(D::Derivative, HP::HalfWeighted{:b,<:Any,<:SemiclassicalJacobi})
66+
P = HP.P
67+
Q = SemiclassicalJacobi(P.t, P.a+1, P.b-1, P.c+1)
68+
b = Q.b
69+
A,B,C = recurrencecoefficients(P)
70+
α,β,γ = recurrencecoefficients(Q)
71+
d = AccumulateAbstractVector(*, A ./ α)
72+
d2 = AccumulateAbstractVector(*, A ./ Vcat(1,α))
73+
v1 = MulAddAccumulate(Vcat(0,0,α[2:∞] ./ α), Vcat(0,β))
74+
v2 = MulAddAccumulate(Vcat(0,0,A[2:∞] ./ α), Vcat(0,B[1], B[2:end] .* d))
75+
76+
HalfWeighted{:b}(Q) * _BandedMatrix(
77+
Vcat(
78+
(-(b:∞) .* v2 .+ ((b+1):∞) .* Vcat(1,v1[2:end] .* d) .+ Vcat(0,(1:∞) .* d2))',
79+
(-((b+1):∞) .* Vcat(1,d))'), ℵ₀, 0,1)
80+
end
81+
82+
@simplify function *(D::Derivative, HP::HalfWeighted{:c,<:Any,<:SemiclassicalJacobi})
83+
P = HP.P
84+
t = P.t
85+
Q = SemiclassicalJacobi(t, P.a+1, P.b+1, P.c-1)
86+
c = Q.c
87+
A,B,C = recurrencecoefficients(P)
88+
α,β,γ = recurrencecoefficients(Q)
89+
d = AccumulateAbstractVector(*, A ./ α)
90+
d2 = AccumulateAbstractVector(*, A ./ Vcat(1,α))
91+
v1 = MulAddAccumulate(Vcat(0,0,α[2:∞] ./ α), Vcat(0,β))
92+
v2 = MulAddAccumulate(Vcat(0,0,A[2:∞] ./ α), Vcat(0,B[1], B[2:end] .* d))
93+
94+
HalfWeighted{:c}(Q) * _BandedMatrix(
95+
Vcat(
96+
(-(c:∞) .* v2 .+ ((c+1):∞) .* Vcat(1,v1[2:end] .* d) .+ Vcat(0,(t:t:∞) .* d2))',
97+
(-((c+1):∞) .* Vcat(1,d))'), ℵ₀, 0,1)
4798
end

test/test_derivative.jl

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -146,51 +146,20 @@ import SemiclassicalOrthogonalPolynomials: MulAddAccumulate, HalfWeighted
146146

147147
t,a,b,c = 2,0.1,0.2,0.3
148148
P = SemiclassicalJacobi(t, a+1, b, c)
149-
Q = SemiclassicalJacobi(t,a,b+1,c+1)
149+
# Q = SemiclassicalJacobi(t,a,b+1,c+1)
150150
HP = HalfWeighted{:a}(P)
151-
HQ = HalfWeighted{:a}(Q)
151+
h = 0.000001
152+
@test (D * HP)[0.1,1:10] (HP[0.1+h,1:10]-HP[0.1,1:10])/h atol=200h
152153

153-
A,B,C = recurrencecoefficients(P);
154-
α,β,γ = recurrencecoefficients(Q);
155-
156-
k = cumprod(A);
157-
κ = cumprod(α);
158-
j = Vector{Float64}(undef, 100)
159-
j[1] = B[1]
160-
for n = 1:length(j)-1
161-
j[n+1] = A[n+1]*j[n] + B[n+1]*k[n]
162-
end
163-
ξ = Vector{Float64}(undef, 100)
164-
ξ[1] = β[1]
165-
for n = 1:length(ξ)-1
166-
ξ[n+1] = α[n+1]*ξ[n] + β[n+1]*κ[n]
167-
end
168-
169-
h = 0.00001
170-
n = 1
171-
x = 0.1
172-
@test (HP[x+h,n]-HP[x,n])/h (a+1) * HQ[x,n] atol=10h
173-
n = 2
174-
@test P[x,n] k[1]*x + j[1]
175-
@test Q[x,n] κ[1]*x + ξ[1]
176-
@test HP[x,n] x^(a+1) * P[x,n]
177-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+1)*(k[1]*x + j[1])+ x * k[1]) atol=10h
178-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+2)*k[1]*x + (a+1)*j[1]) atol=10h
179-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+2)*k[1]*(Q[x,n]-ξ[1])/κ[1] + (a+1)*j[1]) atol=10h
180-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+2)*k[1]/κ[1]*Q[x,n]+ (-(a+2)*k[1]*ξ[1]/κ[1] + (a+1)*j[1])*Q[x,n-1]) atol=10h
181-
182-
n = 3
183-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+n)*k[n-1]/κ[n-1]*Q[x,n]+ (-(a+n)*k[n-1]*ξ[n-1]/κ[n-1] + (a+n-1)*j[n-1])/κ[n-2]*Q[x,n-1]) atol=20h
184-
n = 4
185-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+n)*k[n-1]/κ[n-1]*Q[x,n]+ (-(a+n)*k[n-1]*ξ[n-1]/κ[n-1] + (a+n-1)*j[n-1])/κ[n-2]*Q[x,n-1]) atol=100h
186-
187-
188-
d = AccumulateAbstractVector(*, A ./ α)
189-
# v1 = AccumulateAbstractVector(+, Vcat(1,α) ./ B)
190154

191-
@test (HP[x+h,n]-HP[x,n])/h x^a * ((a+n)*d[n-1]*Q[x,n]+ (-(a+n)*k[n-1]*ξ[n-1]/(κ[n-2]κ[n-1]) + (a+n-1)*j[n-1]/κ[n-2])*Q[x,n-1]) atol=100h
155+
P = SemiclassicalJacobi(t, a, b+1, c)
156+
# Q = SemiclassicalJacobi(t,a+1,b,c+1)
157+
HP = HalfWeighted{:b}(P)
158+
@test (D * HP)[0.1,1:10] (HP[0.1+h,1:10]-HP[0.1,1:10])/h atol=1000h
192159

193-
194-
# Bidiagonal(((P.a+1):∞) .* d, , :U)
160+
P = SemiclassicalJacobi(t, a, b, c+1)
161+
# Q = SemiclassicalJacobi(t,a+1,b+1,c)
162+
HP = HalfWeighted{:c}(P)
163+
@test (D * HP)[0.1,1:10] (HP[0.1+h,1:10]-HP[0.1,1:10])/h atol=2000h
195164
end
196165
end

0 commit comments

Comments
 (0)