Skip to content

Commit ed25acf

Browse files
authored
Change formula for weighted conversion (#121)
* Change formula * Update ci.yml * Update ci.yml * Update ci.yml * Remove closure
1 parent 28b78cb commit ed25acf

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/SemiclassicalOrthogonalPolynomials.jl

+20-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import ClassicalOrthogonalPolynomials: OrthogonalPolynomial, recurrencecoefficie
1717
import InfiniteArrays: OneToInf, InfUnitRange
1818
import ContinuumArrays: basis, Weight, @simplify, AbstractBasisLayout, BasisLayout, MappedBasisLayout, grid, plotgrid, equals_layout, ExpansionLayout
1919
import FillArrays: SquareEye
20-
import HypergeometricFunctions: _₂F₁general2
20+
import HypergeometricFunctions: _₂F₁general2, _₂F₁
21+
import SpecialFunctions: beta
2122

2223
export LanczosPolynomial, Legendre, Normalized, normalize, SemiclassicalJacobi, SemiclassicalJacobiWeight, WeightedSemiclassicalJacobi, OrthogonalPolynomialRatio
2324

@@ -129,6 +130,17 @@ SemiclassicalJacobi{T}(t, a, b, c) where T = SemiclassicalJacobi(convert(T,t), c
129130

130131
WeightedSemiclassicalJacobi{T}(t, a, b, c, P...) where T = SemiclassicalJacobiWeight{T}(convert(T,t), convert(T,a), convert(T,b), convert(T,c)) .* SemiclassicalJacobi{T}(convert(T,t), convert(T,a), convert(T,b), convert(T,c), P...)
131132

133+
# Returns α, β such that P1(x) = β(x-α)
134+
function _linear_coefficients(t, a, b, c)
135+
# beta(a + 1, b + 1) * t^c * _₂F₁(a + 1, -c, a + b + 2, 1/t) is the integral ∫₀¹ wᵗ⁽ᵃᵇᶜ⁾(x) dx
136+
Γᵃ = beta(a + 1, b + 1) * _₂F₁(a + 1, -c, a + b + 2, 1/t)
137+
Γᵃ⁺¹ = beta(a + 2, b + 1) * _₂F₁(a + 2, -c, a + b + 3, 1/t)
138+
Γᵃ⁺² = beta(a + 3, b + 1) * _₂F₁(a + 3, -c, a + b + 4, 1/t)
139+
α = Γᵃ⁺¹/Γᵃ
140+
β = sqrt(Γᵃ / (Γᵃ⁺² - 2α*Γᵃ⁺¹ + α^2*Γᵃ))
141+
return α, β
142+
end
143+
132144
function semiclassical_jacobimatrix(t, a, b, c)
133145
T = float(promote_type(typeof(t), typeof(a), typeof(b), typeof(c)))
134146
if iszero(a) && iszero(b) && c == -one(T)
@@ -471,13 +483,13 @@ function \(w_A::WeightedSemiclassicalJacobi{T}, w_B::WeightedSemiclassicalJacobi
471483
wP = Weighted(P)
472484
wQ = Weighted(Q)
473485
R22 = wP \ wQ
474-
r11 = A.t - 1
475-
qw0 = SemiclassicalJacobiWeight(Q.t, Q.a, zero(Q.b), Q.c)
476-
pw0 = SemiclassicalJacobiWeight(P.t, P.a, zero(P.b), P.c)
477-
r21 = wP[:, 1:2] \ (qw0 .- r11 .* pw0)
478-
d0 = Vcat(r11, R22[band(0)])
479-
d1 = Vcat(r21[begin], R22[band(-1)])
480-
d2 = Vcat(r21[begin+1], R22[band(-2)])
486+
α, β = _linear_coefficients(P.t, P.a, P.b, P.c)
487+
ℓ₁ = A.t - 1
488+
ℓ₂ = 1 + α - A.t
489+
ℓ₃ = inv)
490+
d0 = Vcat(ℓ₁, R22[band(0)])
491+
d1 = Vcat(ℓ₂, R22[band(-1)])
492+
d2 = Vcat(ℓ₃, R22[band(-2)])
481493
data = Hcat(d0, d1, d2)
482494
return _BandedMatrix(data', 1:∞, 2, 0)
483495
elseif (wA.a == A.a) && (wA.b == A.b) && (wA.c == A.c) && (wB.a == B.a) && (wB.b == B.b) && (wB.c == B.c) && isinteger(A.a) && isinteger(A.b) && isinteger(A.c) && isinteger(B.a) && isinteger(B.b) && isinteger(B.c)

test/runtests.jl

+7
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,13 @@ end
673673
end
674674
end
675675

676+
@testset "_linear_coefficients" begin
677+
t, a, b, c = 1.2, 2.3, 0.5, 0.2
678+
P = SemiclassicalJacobi(t, a, b, c)
679+
α, β = SemiclassicalOrthogonalPolynomials._linear_coefficients(t, a, b, c)
680+
@test P[0.2, 2] β * (0.2 - α)
681+
end
682+
676683
include("test_derivative.jl")
677684
include("test_neg1c.jl")
678685
include("test_neg1b.jl")

test/test_neg1b.jl

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ end
246246
@test Q2.X[1:100, 1:100] R2.X[1:100, 1:100]
247247
@test Q3.X[1:100, 1:100] R3.X[1:100, 1:100]
248248
end
249+
249250
@testset "Weighted conversion between b=-1" begin
250251
for (t, a, b, c) in ((2.0, 1 / 2, -1.0, 1 / 2), (2.5, 3 / 2, -1.0, 1 / 2), (2.5, 1.0, -1.0, 2.0))
251252
Q = SemiclassicalJacobi(t, a, b, c)

0 commit comments

Comments
 (0)