Skip to content

Commit 763a4d2

Browse files
committed
Fixed bjgs
1 parent b3fe739 commit 763a4d2

File tree

8 files changed

+92
-32
lines changed

8 files changed

+92
-32
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using ContinuumArrays, FillArrays, InfiniteArrays, Plots
2+
3+
T = Chebyshev()
4+
C = Ultraspherical(2)
5+
D = Derivative(axes(T,1))
6+
A = (C\(D^2*T))+100(C\T)
7+
8+
n = 100
9+
c = [T[[-1,1],1:n]; A[1:n-2,1:n]] \ [1;2;zeros(n-2)]
10+
u = T*Vcat(c,Zeros(∞))
11+
12+
xx = range(-1,1;length=1000)
13+
plot(xx,u[xx])
14+

src/ContinuumArrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclu
1414
ApplyQuasiArray, ApplyQuasiMatrix, LazyQuasiArrayApplyStyle, AbstractQuasiArrayApplyStyle,
1515
LazyQuasiArray, LazyQuasiVector, LazyQuasiMatrix, LazyLayout, LazyQuasiArrayStyle
1616

17-
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative, JacobiWeight, Jacobi, Legendre, Chebyshev, Ultraspherical,
17+
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative,
18+
Jacobi, Legendre, Chebyshev, Ultraspherical,
19+
JacobiWeight, ChebyshevWeight, UltrasphericalWeight,
1820
fullmaterialize
1921

2022
####

src/bases/jacobi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function jacobimatrix(J::Jacobi)
5151
b,a = J.b,J.a
5252
n = 0:
5353
B = @. 2*(n+1)*(n+a+b+1) / ((2n+a+b+1)*(2n+a+b+2))
54-
A = (a^2-b^2) ./ ((2n.+a.+b).*(2n.+a.+b.+2))
54+
A = Vcat((a-b) / (a+b+2), (a^2-b^2) ./ ((2n.+a.+b.+2).*(2n.+a.+b.+4)))
5555
C = @. 2*(n+a)*(n+b) / ((2n+a+b)*(2n+a+b+1))
5656

5757
_BandedMatrix(Vcat(C',A',B'), ∞, 1,1)

src/bases/orthogonalpolynomials.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ end
1313

1414
function forwardrecurrence!(v::AbstractVector{T}, b::AbstractVector, a::AbstractVector, c::AbstractVector, x) where T
1515
isempty(v) && return v
16-
v[1] = one(T) # assume OPs are normalized to one for now
16+
v[1] = one(x) # assume OPs are normalized to one for now
1717
length(v) == 1 && return v
1818
v[2] = (x-a[1])/c[1]
1919
@inbounds for n=3:length(v)
@@ -24,7 +24,7 @@ end
2424

2525
function forwardrecurrence!(v::AbstractVector{T}, b::AbstractVector, ::Zeros{<:Any,1}, c::AbstractVector, x) where T
2626
isempty(v) && return v
27-
v[1] = one(T) # assume OPs are normalized to one for now
27+
v[1] = one(x) # assume OPs are normalized to one for now
2828
length(v) == 1 && return v
2929
v[2] = x/c[1]
3030
@inbounds for n=3:length(v)
@@ -37,7 +37,7 @@ end
3737
function forwardrecurrence!(v::AbstractVector{T}, b::AbstractVector, ::Zeros{<:Any,1}, c::Vcat{<:Any,1,<:Tuple{<:Number,<:AbstractVector}}, x) where T
3838
isempty(v) && return v
3939
c0,c∞ = c.args
40-
v[1] = one(T) # assume OPs are normalized to one for now
40+
v[1] = one(x) # assume OPs are normalized to one for now
4141
length(v) == 1 && return v
4242
v[2] = x/c0
4343
@inbounds for n=3:length(v)
@@ -53,7 +53,7 @@ function forwardrecurrence!(v::AbstractVector{T}, b_v::AbstractFill, ::Zeros{<:A
5353
c∞ = getindex_value(c∞_v)
5454
mbc = -b/c∞
5555
xc = x/c∞
56-
v[1] = one(T) # assume OPs are normalized to one for now
56+
v[1] = one(x) # assume OPs are normalized to one for now
5757
length(v) == 1 && return v
5858
v[2] = x/c0
5959
@inbounds for n=3:length(v)

src/bases/splines.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ function getindex(B::HeavisideSpline{T}, x::Number, k::Int) where T
3131
p = B.points
3232
n = length(p)
3333

34-
x < p[k] && return zero(T)
35-
k < n && x > p[k+1] && return zero(T)
36-
return one(T)
34+
p[k] < x < p[k+1] && return one(T)
35+
p[k] == x && return one(T)/2
36+
p[k+1] == x && return one(T)/2
37+
return zero(T)
3738
end
3839

3940
## Sub-bases

src/bases/ultraspherical.jl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ struct UltrasphericalWeight{T,Λ} <: AbstractJacobiWeight{T}
99
λ::Λ
1010
end
1111

12+
UltrasphericalWeight(λ) = UltrasphericalWeight{typeof(λ),typeof(λ)}(λ)
13+
1214
function getindex(w::UltrasphericalWeight, x::Number)
1315
x axes(w,1) || throw(BoundsError())
1416
(1-x^2)^(w.λ-one(w.λ)/2)
@@ -34,10 +36,8 @@ Ultraspherical(λ::Λ) where Λ = Ultraspherical{Float64,Λ}(λ)
3436

3537
jacobimatrix(C::Chebyshev{T}) where T = _BandedMatrix(Vcat(Fill(one(T)/2,1,∞), Zeros(1,∞), Hcat(one(T), Fill(one(T)/2,1,∞))), ∞, 1, 1)
3638

37-
function jacobimatrix(P::Ultraspherical)
38-
T = promote_type(eltype(P), eltype(X), eltype(U))
39+
function jacobimatrix(P::Ultraspherical{T}) where T
3940
λ = P.λ
40-
λ == U.λ || throw(ArgumentError())
4141
_BandedMatrix(Vcat((((2λ-1):∞) ./ (2 .*((zero(T):∞) .+ λ)))',
4242
Zeros{T}(1,∞),
4343
((one(T):∞) ./ (2 .*((zero(T):∞) .+ λ)))'), ∞, 1, 1)
@@ -50,6 +50,7 @@ end
5050

5151
# Ultraspherical(1)\(D*Chebyshev())
5252
@simplify function \(J::Ultraspherical, *(D::Derivative{<:Any,<:ChebyshevInterval}, S::Chebyshev))
53+
T = promote_type(eltype(J),eltype(D),eltype(S))
5354
(J.λ == 1) || throw(ArgumentError())
5455
_BandedMatrix((zero(eltype(M)):∞)', ∞, -1,1)
5556
end
@@ -59,6 +60,19 @@ end
5960
ApplyQuasiMatrix(*, Ultraspherical{eltype(S)}(1), A)
6061
end
6162

63+
# Ultraspherical(1/2)\(D*Legendre())
64+
@simplify function \(J::Ultraspherical, *(D::Derivative{<:Any,<:ChebyshevInterval}, S::Legendre))
65+
T = promote_type(eltype(J),eltype(D),eltype(S))
66+
(J.λ == 3/2) || throw(ArgumentError())
67+
_BandedMatrix(Ones{T}(1,∞), ∞, -1,1)
68+
end
69+
70+
@simplify function *(D::Derivative{<:Any,<:ChebyshevInterval}, S::Legendre)
71+
A = apply(\,Ultraspherical{eltype(S)}(3/2),applied(*,D,S))
72+
ApplyQuasiMatrix(*, Ultraspherical{eltype(S)}(3/2), A)
73+
end
74+
75+
6276
# Ultraspherical(λ+1)\(D*Ultraspherical(λ))
6377
@simplify function \(J::Ultraspherical, *(D::Derivative{<:Any,<:ChebyshevInterval}, S::Ultraspherical))
6478
(J.λ == S.λ+1) || throw(ArgumentError())
@@ -76,21 +90,28 @@ end
7690
##########
7791

7892

79-
@simplify function \(U::Ultraspherical, C::Chebyshev)
80-
(U.λ == 1) || throw(ArgumentError())
81-
T = promote_type(eltype(U), eltype(C))
82-
BandedMatrix(0 => Vcat([one(T)],Fill(one(T)/2,∞)), 2 => Vcat([-one(T)/2],Fill(-one(T)/2,∞)))
93+
@simplify function \(U::Ultraspherical{<:Any,<:Integer}, C::Chebyshev)
94+
if U.λ == 1
95+
T = promote_type(eltype(U), eltype(C))
96+
BandedMatrix(0 => Vcat([one(T)],Fill(one(T)/2,∞)), 2 => Vcat([-one(T)/2],Fill(-one(T)/2,∞)))
97+
elseif U.λ > 0
98+
(U\Ultraspherical(1)) * (Ultraspherical(1)\C)
99+
else
100+
error("Not implemented")
101+
end
83102
end
84103

85-
@simplify function \(C2::Ultraspherical, C1::Ultraspherical)
104+
@simplify function \(C2::Ultraspherical{<:Any,<:Integer}, C1::Ultraspherical{<:Any,<:Integer})
86105
λ = C1.λ
87106
T = promote_type(eltype(C2), eltype(C1))
88107
if C2.λ == λ+1
89108
_BandedMatrix( Vcat(-./ (1:.+ λ))', Zeros(1,∞), (λ ./ (1:.+ λ))'), ∞, 0, 2)
90109
elseif C2.λ == λ
91110
Eye{T}(∞)
111+
elseif C2.λ > λ
112+
(C2 \ Ultraspherical+1)) * (Ultraspherical+1)\C1)
92113
else
93-
throw(ArgumentError())
114+
error("Not implemented")
94115
end
95116
end
96117

src/operators.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Derivative(axis) = Derivative{Float64}(axis)
151151

152152
axes(D::Derivative) = (D.axis, D.axis)
153153
==(a::Derivative, b::Derivative) = a.axis == b.axis
154+
copy(D::Derivative) = Derivative(copy(D.axis))
154155

155156

156157
function copy(M::QMul2{<:Derivative,<:SubQuasiArray})

test/test_orthogonalpolynomials.jl

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import ContinuumArrays: jacobimatrix
1+
using ContinuumArrays, FillArrays, LazyArrays, BandedMatrices
2+
import ContinuumArrays: jacobimatrix, SimplifyStyle, ∞
3+
import LazyArrays: ApplyStyle, colsupport
4+
25

36
@testset "Ultraspherical" begin
47
T = Chebyshev()
@@ -19,7 +22,7 @@ import ContinuumArrays: jacobimatrix
1922
@test colsupport(D₀,1) == 1:0
2023

2124
D₁ = C\(D*U)
22-
@test D₁ isa BandedMatrix
25+
@test_broken D₁ isa BandedMatrix
2326
@test apply(*,D₁,D₀.args...)[1:10,1:10] == diagm(2 => 4:2:18)
2427
@test (D₁*D₀)[1:10,1:10] == diagm(2 => 4:2:18)
2528

@@ -32,6 +35,36 @@ import ContinuumArrays: jacobimatrix
3235
@test S₁ == diagm(0 => 1 ./ (1:10), 2=> -(1 ./ (3:10)))
3336
end
3437

38+
@testset "Legendre" begin
39+
@test jacobimatrix(Jacobi(0.,0.))[1,1] == 0.0
40+
@test jacobimatrix(Jacobi(0.,0.))[1:10,1:10] == jacobimatrix(Legendre())[1:10,1:10] == jacobimatrix(Ultraspherical(1/2))[1:10,1:10]
41+
@test Jacobi(0.,0.)[0.1,1:10] Legendre()[0.1,1:10] Ultraspherical(1/2)[0.1,1:10]
42+
43+
P = Legendre()
44+
D = Derivative(axes(P,1))
45+
@test Ultraspherical(3/2)\(D*P) isa BandedMatrix{Float64,<:Ones}
46+
end
47+
48+
49+
50+
@testset "Jacobi" begin
51+
b,a = 0.1,0.2
52+
S = Jacobi(b,a)
53+
x = 0.1
54+
@test S[x,1] === 1.0
55+
X = jacobimatrix(S)
56+
@test X[1,1] (a^2-b^2)/((a+b)*(a+b+2))
57+
@test X[2,1] 2/(a+b+2)
58+
@test S[x,2] 0.065
59+
@test S[x,10] 0.22071099583604945
60+
61+
w = JacobiWeight(b,a)
62+
@test w[x] (1+x)^b * (1-x)^a
63+
wS = w.*S
64+
@test wS[0.1,1] w[0.1]
65+
@test wS[0.1,1:2] w[0.1] .* S[0.1,1:2]
66+
end
67+
3568
@testset "Jacobi integer" begin
3669
S = Jacobi(true,true)
3770
W = Diagonal(JacobiWeight(true,true))
@@ -103,18 +136,6 @@ end
103136
@test W[0.1,0.2] 0.0
104137
end
105138

106-
@testset "Jacobi" begin
107-
b,a = 0.1,0.2
108-
S = Jacobi(b,a)
109-
x = 0.1
110-
@test S[x,1] === 1.0
111-
X = jacobimatrix(S)
112-
@test X[1,1] (a^2-b^2)/((a+b)*(a+b+2))
113-
@test X[2,1] 2/(a+b+2)
114-
@test S[x,2] 0.065
115-
@test S[x,10] 0.22071099583604945
116-
end
117-
118139
@testset "P-FEM" begin
119140
S = Jacobi(true,true)
120141
W = Diagonal(JacobiWeight(true,true))

0 commit comments

Comments
 (0)