Skip to content

Commit 3427a72

Browse files
committed
Add tests and fix Stieltjes
1 parent 73c6723 commit 3427a72

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

src/stieltjessquare.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ function stieltjessquare(z, n)
1010
stieltjessquare!(zeros(T,n,n), z)
1111
end
1212

13-
function stieltjessquare_populatefirstcolumn!(A, z)
13+
function stieltjessquare_populatefirstrow!(A, z)
14+
n = size(A,2)
1415
M_p = imlogkernel_vec(n, z+1)
1516
M_m = imlogkernel_vec(n, z-1)
16-
A[:,1] .= M_p .- M_m
17+
A[1,:] .= M_p .- M_m
1718
end
1819

19-
function stieltjessquare_populatefirstrow!(A, z)
20-
M_p = imlogkernel_vec(n, 1-im*z)
21-
M_m = imlogkernel_vec(n, -1-im*z)
22-
m = size(A,1)
23-
A[1,:] .= (-1) .^ (1:m) .* im .* (M_p .- M_m)
20+
function stieltjessquare_populatefirstcolumn!(A, z)
21+
m = size(A,2)
22+
M_p = imlogkernel_vec(m, 1-im*z)
23+
M_m = imlogkernel_vec(m, -1-im*z)
24+
A[:,1] .= (-1) .^ (1:m) .* im .* (M_p .- M_m)
2425
end
2526

2627

2728
function stieltjessquare!(A::AbstractMatrix{T}, z) where T
2829
m,n = size(A)
2930
@assert m == n
3031

31-
stieltjessquare_populatefirstcolumn!(A, z, F_1, F_2)
32-
stieltjessquare_populatefirstrow!(A, z, F_1, F_2)
32+
stieltjessquare_populatefirstcolumn!(A, z)
33+
stieltjessquare_populatefirstrow!(A, z)
3334

3435
# 2nd row/column
3536
for k = 1:m-2
3637
A[k+1,2] = im* (k*A[k,1]/(2k+1) + (k+1)*A[k+2,1]/(2k+1) - z*A[k+1,1])
3738
end
3839

3940
for j = 2:n-2
40-
A[2,j+1] = z*A[1,j+1] - im*(j*A[1,j]/(2j+1) + (j+1)*A[1,k+2]/(2j+1))
41+
A[2,j+1] = z*A[1,j+1] - im*(j*A[1,j]/(2j+1) + (j+1)*A[1,j+2]/(2j+1))
4142
end
4243
# remaining
4344
for= 1:((n-1)÷2-1)
4445
for k =+1:n-(ℓ+2)
45-
A[k+1,ℓ+2] = (im*(2+1)*(k*A[k,ℓ+1]/(2k+1) + (k+1)*A[k+2,ℓ+1]/(2k+1) - z*A[k+1,ℓ+1]) - j*A[k+1,ℓ+1])/(ℓ+1)
46+
A[k+1,ℓ+2] = (-im * (2+1)* z * A[k+1,ℓ+1] + im*(2+1)*(k*A[k,ℓ+1] + (k+1)*A[k+2,ℓ+1])/(2k+1) - *A[k+1,ℓ])/(ℓ+1)
4647
end
4748
for j =+2:n-(ℓ+2)
48-
A[ℓ+2,j+1] = (z*(2k+1)*A[ℓ+1,j+1] - im*(2k+1)*(j*A[ℓ+1,j]/(2j+1) + (j+1)*A[ℓ+1,k+2]/(2j+1)) - k*A[k,ℓ+1])/(k+1)
49+
A[ℓ+2,j+1] = (z*(2+1)*A[ℓ+1,j+1] - im*(2+1)*(j*A[ℓ+1,j] + (j+1)*A[ℓ+1,j+2])/(2j+1) - *A[ℓ,j+1])/(+1)
4950
end
5051
end
5152
A

test/runtests.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
using MultivariateSingularIntegrals, QuadGK, ClassicalOrthogonalPolynomials, LinearAlgebra, Test
22

3+
4+
= (2.0, 2.0im, 2.0+2im, 2.0-2im, -2.0 - 2im)
35
Z = (2, 2im, 2+2im, 2-2im, -2 - 2im, -1.001-1.5im, -0.999-1.5im, -0.5-2im, -1-1.5im, -2+2im, -2, 0.1+0.2im, 0.1+im, 0.1-im, 1+0.1im, -1+0.1im, 1+im, -1+im, -1-im, 1-im)
46
@testset "stieltjes" begin
5-
7+
@testset "accurate for low order" begin
8+
n = 6
9+
for z in
10+
L = stieltjessquare(z,n)
11+
for j = 0:n-1, k=0:n-j-1
12+
q = quadgk(s -> quadgk(t -> iszero(s+im*t) ? 0.0+0.0im : inv(z-(s+im*t)) * legendrep(k,s) * legendrep(j,t), -1, 1, atol=1E-12)[1], -1, 1, atol=1E-12)[1]
13+
@test q L[k+1,j+1] atol=1E-10
14+
end
15+
end
16+
end
17+
18+
@testset "BigFloat" begin
19+
setprecision(2000) do
20+
for z in big.(Z̃)
21+
P = Legendre{BigFloat}()
22+
n = 100
23+
M = Diagonal((P'P)[1:n,1:n])
24+
@test P[big(0.), 1:n]' * inv(M) * stieltjessquare(z, n) * inv(M) * P[big(0.), 1:n] inv(z) atol=1E-40
25+
end
26+
end
27+
end
628
end
729

830
@testset "logkernel" begin

0 commit comments

Comments
 (0)