1
1
using Revise, ApproxFun, MultivariateOrthogonalPolynomials
2
2
import MultivariateOrthogonalPolynomials: checkerboard, icheckerboard, CDisk2CxfPlan
3
3
import ApproxFunBase: totensor
4
- import ApproxFunOrthogonalPolynomials: jacobip, chebyshevt
4
+ import ApproxFunOrthogonalPolynomials: jacobip
5
5
6
6
7
7
8
-
9
-
10
- f = (x,y) -> x* y+ cos (y- 0.1 )+ sin (x)+ 1 ;
11
- ff = Fun (f, ChebyshevDisk (), 1000 )
12
- @test ff (0.1 ,0.2 ) ≈ f (0.1 ,0.2 )
13
-
14
- ff = Fun (f, ChebyshevDisk ())
15
- @test ff (0.1 ,0.2 ) ≈ f (0.1 ,0.2 )
16
-
17
8
function chebydiskeval (c:: AbstractMatrix{T} , r, θ) where T
18
9
ret = zero (T)
19
10
for j = 1 : 2 : size (c,2 ), k= 1 : size (c,1 )
@@ -28,66 +19,83 @@ function chebydiskeval(c::AbstractMatrix{T}, r, θ) where T
28
19
end
29
20
30
21
31
- for (m,ℓ) in ((0 ,1 ),(0 ,2 ),(0 ,3 ), (1 ,0 ), (1 ,1 ), (1 ,2 ), (2 ,0 ), (2 ,1 ),(3 ,0 ),(3 ,4 ))
32
- p1 = (r,θ) -> cos (m* θ) * cos ((2 ℓ+ isodd (m))* acos (r))
33
- f = Fun ((x,y) -> p1 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ())
34
- c = totensor (f. space, chop (f. coefficients,1E-12 ))
35
- @test c[ℓ+ 1 , 2 m+ 1 ] ≈ 1
36
- @test f (0.1 cos (0.2 ),0.1 sin (0.2 )) ≈ chebydiskeval (c, 0.1 , 0.2 )
22
+ @testset " ChebyshevDisk" begin
23
+ f = (x,y) -> x* y+ cos (y- 0.1 )+ sin (x)+ 1 ;
24
+ ff = Fun (f, ChebyshevDisk (), 1000 )
25
+ @test ff (0.1 ,0.2 ) ≈ f (0.1 ,0.2 )
26
+
27
+ ff = Fun (f, ChebyshevDisk ())
28
+ @test ff (0.1 ,0.2 ) ≈ f (0.1 ,0.2 )
29
+
37
30
38
- if m > 0
39
- p2 = (r,θ) -> sin (m* θ) * cos ((2 ℓ+ isodd (m))* acos (r))
40
- f = Fun ((x,y) -> p2 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ())
31
+ for (m,ℓ) in (( 0 , 1 ),( 0 , 2 ),( 0 , 3 ), ( 1 , 0 ), ( 1 , 1 ), ( 1 , 2 ), ( 2 , 0 ), ( 2 , 1 ),( 3 , 0 ),( 3 , 4 ))
32
+ p1 = (r,θ) -> cos (m* θ) * cos ((2 ℓ+ isodd (m))* acos (r))
33
+ f = Fun ((x,y) -> p1 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ())
41
34
c = totensor (f. space, chop (f. coefficients,1E-12 ))
42
- @test c[ℓ+ 1 , 2 m] ≈ 1
35
+ @test c[ℓ+ 1 , 2 m+ 1 ] ≈ 1
43
36
@test f (0.1 cos (0.2 ),0.1 sin (0.2 )) ≈ chebydiskeval (c, 0.1 , 0.2 )
37
+
38
+ if m > 0
39
+ p2 = (r,θ) -> sin (m* θ) * cos ((2 ℓ+ isodd (m))* acos (r))
40
+ f = Fun ((x,y) -> p2 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ())
41
+ c = totensor (f. space, chop (f. coefficients,1E-12 ))
42
+ @test c[ℓ+ 1 , 2 m] ≈ 1
43
+ @test f (0.1 cos (0.2 ),0.1 sin (0.2 )) ≈ chebydiskeval (c, 0.1 , 0.2 )
44
+ end
44
45
end
45
46
end
46
47
47
- f = Fun ((x,y) -> 1 , ChebyshevDisk ()); n = 1 ;
48
+
49
+ @testset " disk transform" begin
50
+ f = Fun ((x,y) -> 1 , ChebyshevDisk ()); n = 1 ;
48
51
c = totensor (f. space, f. coefficients)
49
52
P = CDisk2CxfPlan (n)
50
53
d = P \ c
51
54
@test d ≈ [1 / sqrt (2 )]
52
- f = Fun ((x,y) -> y, ChebyshevDisk ()); n = 2 ;
55
+ f = Fun ((x,y) -> y, ChebyshevDisk ()); n = 2 ;
53
56
c = totensor (f. space, f. coefficients)
54
57
c = pad (c, n, 4 n- 3 )
55
58
P = CDisk2CxfPlan (n)
56
59
d = P \ c
57
- @test d ≈ [0.0 0.5 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 ]
60
+ @test d ≈ [0.0 0.5 0.0 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 ]
58
61
59
- f = Fun ((x,y) -> x, ChebyshevDisk ()); n = 2 ;
62
+ f = Fun ((x,y) -> x, ChebyshevDisk ()); n = 2 ;
60
63
c = totensor (f. space, f. coefficients)
61
64
c = pad (c, n, 4 n- 3 )
62
65
P = CDisk2CxfPlan (n)
63
66
d = P \ c
64
- @test d ≈ [0.0 0.0 0.5 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 ]
65
-
66
-
67
- # m,ℓ = (0,2);
68
- # m,ℓ = (1,1);
69
- # m,ℓ = (2,2);
70
-
71
-
72
- m,ℓ = (2 ,4 );
73
- p1 = (r,θ) -> sqrt (2 ℓ+ 2 )* r^ m* jacobip ((ℓ- m)÷ 2 , m, 0 , 2 r^ 2 - 1 )* cos (m* θ)/ sqrt (2 π)
74
- f = Fun ((x,y) -> p1 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ());
75
- @test f (0.1 * cos (0.2 ),0.1 * sin (0.2 )) ≈ p1 (0.1 ,0.2 )
76
- c = totensor (f. space, chop (f. coefficients,1E-12 ))
77
- @test chebydiskeval (c, 0.1 , 0.2 ) ≈ p1 (0.1 ,0.2 )
78
-
79
-
80
- n = size (c,1 ); c = sqrt (2 π)* pad (c,n,4 n- 3 )
81
- P = CDisk2CxfPlan (n)
82
- d = P \ c
83
- @test d[(ℓ- m)÷ 2 , 2 m+ 1 ] ≈ 0
84
- @test d[(ℓ- m)÷ 2 + 1 , 2 m+ 1 ] ≈ 1
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
67
+ @test d ≈ [0.0 0.0 0.5 0.0 0.0 ; 0.0 0.0 0.0 0.0 0.0 ]
68
+
69
+
70
+ @testset " explicit polynomial" begin
71
+ p1 = (r,θ) -> sqrt (10 )* r^ 2 * (4 r^ 2 - 3 )* cos (2 θ)/ sqrt (π)
72
+ f = Fun ((x,y) -> p1 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ());
73
+ @test f (0.1 * cos (0.2 ),0.1 * sin (0.2 )) ≈ p1 (0.1 ,0.2 )
74
+ c = totensor (f. space, chop (f. coefficients,1E-12 ))
75
+ @test chebydiskeval (c, 0.1 , 0.2 ) ≈ p1 (0.1 ,0.2 )
76
+ n = size (c,1 ); c = sqrt (π)* pad (c,n,4 n- 3 )
77
+ P = CDisk2CxfPlan (n)
78
+ d = P \ c
79
+ @test d[1 ,4 ] ≈ 0 atol= 1E-13
80
+ @test d[2 ,5 ] ≈ 1
81
+ end
82
+ @testset " different m and ℓ" begin
83
+ for (m,ℓ) in ((0 ,2 ), (1 ,1 ), (2 ,2 ), (2 ,6 ), (3 ,3 ))
84
+ p1 = (r,θ) -> sqrt (2 ℓ+ 2 )* r^ m* jacobip ((ℓ- m)÷ 2 , 0 , m, 2 r^ 2 - 1 )* cos (m* θ)/ sqrt (π)
85
+ f = Fun ((x,y) -> p1 (sqrt (x^ 2 + y^ 2 ), atan (y,x)), ChebyshevDisk ());
86
+ @test f (0.1 * cos (0.2 ),0.1 * sin (0.2 )) ≈ p1 (0.1 ,0.2 )
87
+ c = totensor (f. space, chop (f. coefficients,1E-12 ))
88
+ @test chebydiskeval (c, 0.1 , 0.2 ) ≈ p1 (0.1 ,0.2 )
89
+
90
+ n = size (c,1 ); c = sqrt (π)* pad (c,n,4 n- 3 )
91
+ P = CDisk2CxfPlan (n)
92
+ d = P \ c
93
+ @test norm (d[:, 1 : 2 m]) ≈ 0 atol = 1E-13
94
+ @test norm (d[1 : (ℓ- m)÷ 2 , 2 m+ 1 ]) ≈ 0 atol = 1E-13
95
+ @test d[(ℓ- m)÷ 2 + 1 , 2 m+ 1 ] ≈ 1
96
+ @test norm (d[(ℓ- m)÷ 2 + 2 : end , 2 m+ 1 ]) ≈ 0 atol = 1E-13
97
+ @test norm (d[:, 2 m+ 2 : end ]) ≈ 0 atol = 1E-13
98
+ end
99
+ end
100
+ end
93
101
0 commit comments