Skip to content

Commit b1373cf

Browse files
authored
Support Clenshaw with Weighted (#262)
* Support Clenshaw with Weighted * non symmetric example
1 parent ba1bf45 commit b1373cf

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ClassicalOrthogonalPolynomials"
22
uuid = "b30e2e7b-c4ee-47da-9d5f-2c5c27239acd"
3-
version = "0.15.12"
3+
version = "0.15.13"
44
authors = ["Sheehan Olver <[email protected]>"]
55

66
[deps]

examples/nonlinearode.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
####
2+
# solve
3+
#
4+
# -u'' + u^2 = 1 + x
5+
# u(±1) = 0
6+
#
7+
# using integrated Legendre w/ Newton iteration.
8+
###
9+
10+
using ClassicalOrthogonalPolynomials, Plots
11+
12+
P = Legendre(); C = Ultraspherical(3/2); W = Weighted(C)
13+
x = axes(P,1)
14+
Δ = diff(W)'diff(W)
15+
M = W'W
16+
b = W'*(1 .+ x)
17+
F = u -> Δ*u + M * (W\((W*u) .^ 2)) - b
18+
J = u -> Δ + 2*M * (W \ ((P * (P\(W*u))) .* W))
19+
20+
21+
u = zeros(∞)
22+
while norm(F(u)) 1E-12
23+
u -= J(u) \ F(u)
24+
end
25+
26+
27+
plot(W*u)

src/clenshaw.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ Base.@propagate_inbounds getindex(f::Mul{<:WeightedOPLayout,<:AbstractPaddedLayo
107107
weight(f.A)[x] * (unweighted(f.A) * f.B)[x, j...]
108108

109109

110-
# TODO: generalise this to be trait based
111110
function layout_broadcasted(::Tuple{ExpansionLayout{<:AbstractOPLayout},AbstractOPLayout}, ::typeof(*), a, P)
112111
axes(a,1) == axes(P,1) || throw(DimensionMismatch())
113112
P * Clenshaw(a, P)
114113
end
115114

115+
function layout_broadcasted(::Tuple{ExpansionLayout{<:AbstractOPLayout},WeightedOPLayout}, ::typeof(*), a, W)
116+
P = W.P
117+
axes(a,1) == axes(P,1) || throw(DimensionMismatch())
118+
W * Clenshaw(a, P)
119+
end
120+
121+
116122
# TODO: layout_broadcasted
117123
function broadcasted(::LazyQuasiArrayStyle{2}, ::typeof(*), a::ApplyQuasiVector{<:Any,typeof(*),<:Tuple{SubQuasiArray{<:Any,2,<:OrthogonalPolynomial,<:Tuple{AbstractAffineQuasiVector,Slice}},Any}}, V::SubQuasiArray{<:Any,2,<:OrthogonalPolynomial,<:Tuple{AbstractAffineQuasiVector,Any}})
118124
axes(a,1) == axes(V,1) || throw(DimensionMismatch())

test/test_chebyshev.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,13 @@ import BandedMatrices: isbanded
595595
op = 2 * f .* T
596596
@test op[0.1,1:5] 2f[0.1] * T[0.1,1:5]
597597
end
598+
599+
@testset "Clenshaw for Weighted" begin
600+
T = ChebyshevT(); W = Weighted(T)
601+
a = expand(T, exp)
602+
@test W \ (a .* W) isa Clenshaw
603+
@test (a .* W)[0.1,1:5] a[0.1] * W[0.1,1:5]
604+
end
598605
end
599606

600607
struct QuadraticMap{T} <: Map{T} end

0 commit comments

Comments
 (0)