Skip to content

Commit 089ad3c

Browse files
authored
add Jacobi matrices for RectPolynomial (#174)
* Revert "Revert "add Jacobi matrices for RectPolynomial"" This reverts commit 3a563d5. * fix tests
1 parent 3a563d5 commit 089ad3c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/rect.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ function getindex(P::RectPolynomial, xy::StaticVector{2}, JR::BlockOneTo)
3636
N = size(JR,1)
3737
DiagTrav(A[x,OneTo(N)] .* B[y,OneTo(N)]')
3838
end
39+
# Actually Jxᵀ
40+
function jacobimatrix(::Val{1}, P::RectPolynomial)
41+
A,B = P.args
42+
X = jacobimatrix(A)
43+
KronTrav(Eye{eltype(X)}(∞), X)
44+
end
45+
# Actually Jyᵀ
46+
function jacobimatrix(::Val{2}, P::RectPolynomial)
47+
A,B = P.args
48+
Y = jacobimatrix(B)
49+
KronTrav(Y, Eye{eltype(Y)}(∞))
50+
end
3951
@simplify function *(Dx::PartialDerivative{1}, P::RectPolynomial)
4052
A,B = P.args
4153
U,M = (Derivative(axes(A,1))*A).args
@@ -150,4 +162,4 @@ function transform_ldiv(K::KronPolynomial{d,V,<:Fill{<:Legendre}}, f::Union{Abst
150162
T = KronPolynomial{d}(Fill(ChebyshevT{V}(), size(K.args)...))
151163
dat = (T \ f).array
152164
DiagTrav(pad(FastTransforms.th_cheb2leg(paddeddata(dat)), axes(dat)...))
153-
end
165+
end

test/test_rect.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ using ContinuumArrays: plotgridvalues
4343
@test f[SVector(0.1,0.2)] exp(0.1*cos(0.1))
4444
end
4545

46+
@testset "Jacobi matrices" begin
47+
T = ChebyshevT()
48+
U = ChebyshevU()
49+
TU = RectPolynomial(T, U)
50+
X = jacobimatrix(Val{1}(), TU)
51+
Y = jacobimatrix(Val{2}(), TU)
52+
𝐱 = axes(TU, 1)
53+
x, y = first.(𝐱), last.(𝐱)
54+
N = 10
55+
KR = Block.(1:N)
56+
@test (TU \ (x .* TU))[KR,KR] == X[KR,KR]
57+
@test (TU \ (y .* TU))[KR,KR] == Y[KR,KR]
58+
f = expand(TU, splat((x,y) -> exp(x*cos(y-0.1))))
59+
g = expand(TU, splat((x,y) -> x*exp(x*cos(y-0.1))))
60+
h = expand(TU, splat((x,y) -> y*exp(x*cos(y-0.1))))
61+
@test (X * (TU \ f))[KR] (TU \ g)[KR]
62+
@test (Y * (TU \ f))[KR] (TU \ h)[KR]
63+
end
64+
4665
@testset "Conversion" begin
4766
T = ChebyshevT()
4867
U = ChebyshevU()
@@ -119,4 +138,4 @@ using ContinuumArrays: plotgridvalues
119138
@test x == SVector.(ChebyshevGrid{2}(40), ChebyshevGrid{2}(40)')
120139
@test F == ones(40,40)
121140
end
122-
end
141+
end

0 commit comments

Comments
 (0)