Skip to content

Commit 771cf31

Browse files
authored
Support 3-interval Hilbert (#74)
* Support 3-interval Hilbert * test 3-interval ODE solve
1 parent a9c43f0 commit 771cf31

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
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.4.8"
4+
version = "0.4.9"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -29,7 +29,7 @@ ArrayLayouts = "0.7.5"
2929
BandedMatrices = "0.16.11"
3030
BlockArrays = "0.16.6"
3131
BlockBandedMatrices = "0.11"
32-
ContinuumArrays = "0.9.1"
32+
ContinuumArrays = "0.9.4"
3333
DomainSets = "0.5.6"
3434
FFTW = "1.1"
3535
FastGaussQuadrature = "0.4.3"

src/stieltjes.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,17 @@ end
308308
###
309309

310310

311-
@simplify function *(H::Hilbert, S::PiecewiseInterlace)
312-
axes(H,2) == axes(S,1) || throw(DimensionMismatch())
313-
@assert length(S.args) == 2
314-
a,b = S.args
315-
xa,xb = axes(a,1),axes(b,1)
316-
Ha_a = inv.(xa .- xa') * a
317-
Ha_b = inv.(xb .- xa') * a
318-
Hb_a = inv.(xa .- xb') * b
319-
Hb_b = inv.(xb .- xb') * b
320-
c,d = Hb_a.args[1], Ha_b.args[1]
321-
A,B,C,D = unitblocks(c \ Ha_a), unitblocks(c \ Hb_a), unitblocks(d \ Ha_b), unitblocks(d \ Hb_b)
322-
PiecewiseInterlace(c,d) * BlockBroadcastArray{promote_type(eltype(H),eltype(S))}(hvcat, 2, A, B, C, D)
311+
@simplify function *(H::Hilbert, W::PiecewiseInterlace)
312+
axes(H,2) == axes(W,1) || throw(DimensionMismatch())
313+
Hs = broadcast(function(a,b)
314+
x,t = axes(a,1),axes(b,1)
315+
H = inv.(x .- t') * b
316+
H
317+
end, [W.args...], permutedims([W.args...]))
318+
N = length(W.args)
319+
Ts = [broadcastbasis(+, broadcast(H -> H.args[1], Hs[k,:])...) for k=1:N]
320+
Ms = broadcast((T,H) -> unitblocks(T\H), Ts, Hs)
321+
PiecewiseInterlace(Ts...) * BlockBroadcastArray{promote_type(eltype(H),eltype(W))}(hvcat, N, permutedims(Ms)...)
323322
end
324323

325324

test/test_interlace.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ import ClassicalOrthogonalPolynomials: PiecewiseInterlace, plotgrid
5858
# Δ \ (W'exp.(x))
5959
end
6060

61+
@testset "three-interval ODE" begin
62+
d = (-1..0),(0..1),(1..2)
63+
T = PiecewiseInterlace(chebyshevt.(d)...)
64+
U = PiecewiseInterlace(chebyshevu.(d)...)
65+
66+
D = U \ (Derivative(axes(T,1))*T)
67+
C = U \ T
68+
69+
A = BlockVcat(T[-1,:]',
70+
BlockBroadcastArray(vcat,unitblocks(T.args[1][end,:]),-unitblocks(T.args[2][begin,:]),Zeros((unitblocks(axes(T.args[3],2)),)))',
71+
BlockBroadcastArray(vcat,Zeros((unitblocks(axes(T.args[1],2)),)),unitblocks(T.args[2][end,:]),-unitblocks(T.args[3][begin,:]))',
72+
D-C)
73+
N = 20
74+
M = BlockArray(A[Block.(1:N+2), Block.(1:N)])
75+
76+
u = M \ [exp(-1); zeros(size(M,1)-1)]
77+
x = axes(T,1)
78+
79+
F = factorize(T[:,Block.(Base.OneTo(N))])
80+
@test F \ exp.(x) (T \ exp.(x))[Block.(1:N)] u
81+
end
82+
83+
6184
@testset "plot" begin
6285
T1,T2 = chebyshevt(-1..0), chebyshevt(0..1)
6386
T = PiecewiseInterlace(T1, T2)

test/test_stieltjes.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ end
266266

267267
@test Z * H[:,1] - H[:,2]/2 [sum(W[:,1]); zeros(∞)]
268268
@test norm(-H[:,1]/2 + Z * H[:,2] - H[:,3]/2)  1E-12
269-
269+
270270
L = U \ ((x.^2 .- 1) .* Derivative(x) * T - x .* T)
271271
c = T \ sqrt.(x.^2 .- 1)
272272
@test [T[begin,:]'; L] \ [sqrt(2^2-1); zeros(∞)] c
@@ -351,6 +351,25 @@ end
351351
end
352352
end
353353

354+
@testset "three-interval" begin
355+
d = (-2..(-1), 0..1, 2..3)
356+
T = PiecewiseInterlace(chebyshevt.(d)...)
357+
U = PiecewiseInterlace(chebyshevu.(d)...)
358+
W = PiecewiseInterlace(Weighted.(U.args)...)
359+
x = axes(W,1)
360+
H = T \ inv.(x .- x') * W
361+
c = W \ broadcast(x -> exp(x) *
362+
if -2  x  -1
363+
sqrt(x+2)sqrt(-1-x)
364+
elseif 0  x  1
365+
sqrt(1-x)sqrt(x)
366+
else
367+
sqrt(x-2)sqrt(3-x)
368+
end, x)
369+
f = W * c
370+
@test T[0.5,1:200]'*(H*c)[1:200] -3.0366466972156143
371+
end
372+
354373
#################################################
355374
# ∫f(x)g(x)(t-x)^a dx evaluation where f and g in Legendre
356375
#################################################

0 commit comments

Comments
 (0)