|
1 | 1 | using MultivariateOrthogonalPolynomials, ClassicalOrthogonalPolynomials, StaticArrays, LinearAlgebra, BlockArrays, FillArrays, Base64, LazyBandedMatrices, ArrayLayouts, Random, StatsBase, Test |
2 | | -using ClassicalOrthogonalPolynomials: expand, coefficients, recurrencecoefficients |
| 2 | +using ClassicalOrthogonalPolynomials: expand, coefficients, recurrencecoefficients, normalized |
3 | 3 | using MultivariateOrthogonalPolynomials: weaklaplacian, ClenshawKron |
4 | | -using ContinuumArrays: plotgridvalues, ExpansionLayout |
| 4 | +using ContinuumArrays: plotgridvalues, ExpansionLayout, basis, grid |
5 | 5 | using Base: oneto |
6 | 6 |
|
7 | 7 | Random.seed!(3242) |
@@ -32,17 +32,47 @@ Random.seed!(3242) |
32 | 32 | @test T²ₙ \ one.(x) == [1; zeros(14)] |
33 | 33 | @test (T² \ x)[1:5] ≈[0;1;zeros(3)] |
34 | 34 |
|
35 | | - f = expand(T², splat((x,y) -> exp(x*cos(y-0.1)))) |
36 | | - @test f[SVector(0.1,0.2)] ≈ exp(0.1*cos(0.1)) |
| 35 | + f = splat((x,y) -> exp(x*cos(y-0.1))) |
| 36 | + 𝐟 = expand(T², f) |
| 37 | + @test 𝐟[SVector(0.1,0.2)] ≈ f(SVector(0.1,0.2)) |
37 | 38 |
|
38 | 39 | U² = RectPolynomial(Fill(U, 2)) |
39 | | - |
40 | | - @test f[SVector(0.1,0.2)] ≈ exp(0.1cos(0.1)) |
| 40 | + 𝐟 = expand(U², f) |
| 41 | + @test 𝐟[SVector(0.1,0.2)] ≈ f(SVector(0.1,0.2)) |
41 | 42 |
|
42 | 43 | TU = RectPolynomial(T,U) |
43 | | - x,F = ClassicalOrthogonalPolynomials.plan_grid_transform(TU, Block(5)) |
44 | | - f = expand(TU, splat((x,y) -> exp(x*cos(y-0.1)))) |
45 | | - @test f[SVector(0.1,0.2)] ≈ exp(0.1*cos(0.1)) |
| 44 | + 𝐟 = expand(TU, f) |
| 45 | + @test 𝐟[SVector(0.1,0.2)] ≈ f(SVector(0.1,0.2)) |
| 46 | + |
| 47 | + @testset "matrix" begin |
| 48 | + N = 10 |
| 49 | + 𝐱 = grid(T², Block(N)) |
| 50 | + |
| 51 | + @test T²[𝐱,1] == ones(N,N) |
| 52 | + @test T²[𝐱,2] == first.(𝐱) |
| 53 | + @test T²[𝐱,1:3] == T²[𝐱,Block.(Base.OneTo(2))] == T²[𝐱,[Block(1),Block(2)]] == [ones(N,N) ;;; first.(𝐱) ;;; last.(𝐱)] |
| 54 | + @test T²[𝐱,Block(1)] == [ones(N,N) ;;;] |
| 55 | + @test T²[𝐱,[1 2; 3 4]] ≈ [T²[𝐱,[1,3]] ;;;; T²[𝐱,[2,4]]] |
| 56 | + |
| 57 | + |
| 58 | + F = plan_transform(T², Block(N)) |
| 59 | + @test F * f.(𝐱) ≈ transform(T², f)[Block.(1:N)] atol=1E-6 |
| 60 | + |
| 61 | + x,y = coordinates(ChebyshevInterval()^2) |
| 62 | + A = [one(x) x y] |
| 63 | + F = plan_transform(T², (Block(N), 3), 1) |
| 64 | + @test F * A[𝐱,:] ≈ [I(3); zeros(52,3)] |
| 65 | + |
| 66 | + @test T² \ A ≈ [I(3); Zeros(∞,3)] |
| 67 | + |
| 68 | + P² = RectPolynomial(Fill(Legendre(),2)) |
| 69 | + F = plan_transform(P², (Block(N),3), 1) |
| 70 | + 𝐱 = grid(P², Block(N)) |
| 71 | + @test F * A[𝐱,:] ≈ P²[:,Block.(Base.OneTo(N))] \ A ≈ [I(3); Zeros(52,3)] |
| 72 | + |
| 73 | + F = plan_transform(normalized(P²), (Block(N),3), 1) |
| 74 | + @test F * A[𝐱,:] ≈ normalized(P²)[:,Block.(Base.OneTo(N))] \ A ≈ [Diagonal([2, 2/sqrt(3), 2/sqrt(3)]); Zeros(52,3)] |
| 75 | + end |
46 | 76 | end |
47 | 77 |
|
48 | 78 | @testset "Jacobi matrices" begin |
@@ -254,4 +284,17 @@ Random.seed!(3242) |
254 | 284 | @test sample(f) isa SVector |
255 | 285 | @test sum(sample(f, 100_000))/100_000 ≈ [sum(x .* f)/sum(f),sum(y .* f)/sum(f)] rtol=1E-1 |
256 | 286 | end |
| 287 | + |
| 288 | + @testset "qr" begin |
| 289 | + x,y = coordinates(ChebyshevInterval()^2) |
| 290 | + A = [one(x) cos.(x) cos.(y)] |
| 291 | + |
| 292 | + @test A[SVector(0.1,0.2),1] ≈ 1 |
| 293 | + @test A[SVector(0.1,0.2),1:3] ≈ A[SVector(0.1,0.2),:] ≈ [1,cos(0.1),cos(0.2)] |
| 294 | + |
| 295 | + Q,R = qr(A) |
| 296 | + @test Q[SVector(0.1,0.2),1] ≈ 1/2 |
| 297 | + @test Q[SVector(0.1,0.2),2] ≈ (cos(0.1) - sin(1))/sqrt(2cos(2) + sin(2)) |
| 298 | + @test Q[SVector(0.1,0.2),3] ≈ (cos(0.2) - sin(1))/sqrt(2cos(2) + sin(2)) |
| 299 | + end |
257 | 300 | end |
0 commit comments