@@ -5,8 +5,9 @@ using Test
55using LinearAlgebra
66using SpecialFunctions
77using ApproxFunBaseTest: testfunctional, testbandedoperator
8+ include (joinpath (@__DIR__ , " testutils.jl" ))
89
9- @testset " Fractional" begin
10+ @verbose @ testset " Fractional" begin
1011 @testset " Jupyter example" begin
1112 S = Legendre () ⊕ JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
1213 @time Q½ = LeftIntegral (S,0.5 )
@@ -25,122 +26,116 @@ using ApproxFunBaseTest: testfunctional, testbandedoperator
2526
2627 # # Avazzadev et al
2728
28- # Example 1
29-
30- x= Fun (0 .. 1 )
31- Q= gamma (0.5 )* LeftIntegral (0.5 )
32- @time f= (2 / 105 * sqrt (x)* (105 - 56 x^ 2 + 48 x^ 3 ))
33- u= Q\ f
34- @test norm (u- (x^ 3 - x^ 2 + 1 ))< 100 eps ()
35-
36-
37- # Example 2
38-
39- x= Fun (0 .. 1 )
40- Q= gamma (0.5 )* LeftIntegral (0.5 )
41- u= Q\ (exp (x)- 1 )
42- @time @test norm (u- exp (x)* erf (sqrt (x))/ sqrt (π)) < 100 eps () # 5.0036177384681187e-14
43-
44-
45- # Example 3
46- x= Fun (0 .. 1 )
47- Q= gamma (1 / 5 )* LeftIntegral (1 / 5 )
48- u= Q\ (x+ 1 )
49- @test norm (u- (1 + 1.25 x)* sin (0.8 π)/ (π* x^ (1 / 5 ))) < 10 eps ()
50-
51- # Example 4
52- x= Fun (0 .. 1 )
53- Q= gamma (1 - 1 / 3 )* LeftIntegral (1 - 1 / 3 )
54- u= Q\ x^ (7 / 6 )
55- @test norm (u- 7 * gamma (1 / 6 )/ (18 * sqrt (π)* gamma (2 / 3 ))* sqrt (x)) < 100 eps ()
56-
57-
58- # Example 5
59-
60- d= Interval (0 ,1 )
61- x= Fun (d)
62- f= x+ 4 / 3 * x^ (3 / 2 )
63- S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
64- Q= gamma (.5 )* LeftIntegral (S,.5 )
65-
66-
67- @time @test sum (f/ sqrt (1 - x)) ≈ last (Q* f)
68-
69- L= I+ Q
70- @test last (L. ops[2 ]* f) ≈ last (Q* f)
71- @test last (L* f) ≈ last (f)+ last (Q* f)
72-
73- @time u= L\ f
74- @test norm (u- x) < 10 eps ()
75-
76-
77- # Example 6
29+ @testset " Example 1" begin
30+ x= Fun (0 .. 1 )
31+ Q= gamma (0.5 )* LeftIntegral (0.5 )
32+ @time f= (2 / 105 * sqrt (x)* (105 - 56 x^ 2 + 48 x^ 3 ))
33+ u= Q\ f
34+ @test norm (u- (x^ 3 - x^ 2 + 1 ))< 100 eps ()
35+ end
7836
79- d= Interval (0 ,1 )
80- x= Fun (d)
81- @time f= x^ 2 + 16 / 15 * x^ (5 / 2 )
82- S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
83- Q= gamma (.5 )* LeftIntegral (S,.5 )
84- L= I+ Q
85- @time u= L\ f
86- @test norm (u- x^ 2 ) < 10 eps ()
8737
88- # Example 7
38+ @testset " Example 2" begin
39+ x= Fun (0 .. 1 )
40+ Q= gamma (0.5 )* LeftIntegral (0.5 )
41+ u= Q\ (exp (x)- 1 )
42+ @time @test norm (u- exp (x)* erf (sqrt (x))/ sqrt (π)) < 100 eps () # 5.0036177384681187e-14
43+ end
8944
90- d= Interval (0. ,1. )
91- x= Fun (d)
92- f= 2 sqrt (x)
93- S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
94- Q= gamma (.5 )* LeftIntegral (S,.5 )
95- @time L= I+ Q
96- u= L\ f
9745
98- @time @test norm (1 - exp (π* x)* erfc (sqrt (π* x))- u) < 100 eps ()
46+ @testset " Example 3" begin
47+ x= Fun (0 .. 1 )
48+ Q= gamma (1 / 5 )* LeftIntegral (1 / 5 )
49+ u= Q\ (x+ 1 )
50+ @test norm (u- (1 + 1.25 x)* sin (0.8 π)/ (π* x^ (1 / 5 ))) < 10 eps ()
51+ end
9952
53+ @testset " Example 4" begin
54+ x= Fun (0 .. 1 )
55+ Q= gamma (1 - 1 / 3 )* LeftIntegral (1 - 1 / 3 )
56+ u= Q\ x^ (7 / 6 )
57+ @test norm (u- 7 * gamma (1 / 6 )/ (18 * sqrt (π)* gamma (2 / 3 ))* sqrt (x)) < 100 eps ()
58+ end
10059
101- # Example 8
60+ @testset " Example 5" begin
61+ d= Interval (0 ,1 )
62+ x= Fun (d)
63+ f= x+ 4 / 3 * x^ (3 / 2 )
64+ S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
65+ Q= gamma (.5 )* LeftIntegral (S,.5 )
66+ @time @test sum (f/ sqrt (1 - x)) ≈ last (Q* f)
10267
103- d= Interval (0. ,1. )
104- x= Fun (d)
105- @time f= 1 / (x+ 1 )+ 2 * Fun (x-> asinh (sqrt (x))/ sqrt (1 + x),JacobiWeight (.5 ,0. ,d))
106- S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
107- Q= gamma (.5 )* LeftIntegral (S,.5 )
108- L= I+ Q
109- u= L\ f
110- @test norm ((u- 1 / (x+ 1 )). coefficients) < 1000 eps () # 1.2011889731154679e-14
68+ L= I+ Q
69+ @test last (L. ops[2 ]* f) ≈ last (Q* f)
70+ @test last (L* f) ≈ last (f)+ last (Q* f)
11171
72+ @time u= L\ f
73+ @test norm (u- x) < 10 eps ()
74+ end
11275
76+ @testset " Example 6" begin
77+ d= Interval (0 ,1 )
78+ x= Fun (d)
79+ @time f= x^ 2 + 16 / 15 * x^ (5 / 2 )
80+ S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
81+ Q= gamma (.5 )* LeftIntegral (S,.5 )
82+ L= I+ Q
83+ @time u= L\ f
84+ @test norm (u- x^ 2 ) < 10 eps ()
85+ end
11386
87+ @testset " Example 7" begin
88+ d= Interval (0. ,1. )
89+ x= Fun (d)
90+ f= 2 sqrt (x)
91+ S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
92+ Q= gamma (.5 )* LeftIntegral (S,.5 )
93+ @time L= I+ Q
94+ u= L\ f
11495
115- # # Test for bug
96+ @time @test norm (1 - exp (π* x)* erfc (sqrt (π* x))- u) < 100 eps ()
97+ end
11698
117- QL = LeftIntegral (0.5 ) : Legendre () → JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
118- QU = LeftIntegral (0.5 ) : JacobiWeight (0.5 ,0. ,Ultraspherical (1 )) → Legendre ()
11999
100+ @testset " Example 8" begin
101+ d= Interval (0. ,1. )
102+ x= Fun (d)
103+ @time f= 1 / (x+ 1 )+ 2 * Fun (x-> asinh (sqrt (x))/ sqrt (1 + x),JacobiWeight (.5 ,0. ,d))
104+ S= Legendre (d)⊕ JacobiWeight (.5 ,0. ,Jacobi (.5 ,.5 ,d))
105+ Q= gamma (.5 )* LeftIntegral (S,.5 )
106+ L= I+ Q
107+ u= L\ f
108+ @test norm ((u- 1 / (x+ 1 )). coefficients) < 1000 eps () # 1.2011889731154679e-14
109+ end
120110
121- λ= 0.25
122- @time L= [λ* I QU; QL λ* I]
123- @test L[2 ,5 ] ≈ 0.
124111
125112
113+ @testset " Test for bug" begin
114+ QL = LeftIntegral (0.5 ) : Legendre () → JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
115+ QU = LeftIntegral (0.5 ) : JacobiWeight (0.5 ,0. ,Ultraspherical (1 )) → Legendre ()
126116
127- # # Paper examples
117+ λ= 0.25
118+ @time L= [λ* I QU; QL λ* I]
119+ @test L[2 ,5 ] ≈ 0.
120+ end
128121
129- S= Legendre ()⊕ JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
130- Q½= LeftIntegral (S,0.5 )
122+ @testset " paper examples" begin
123+ S= Legendre ()⊕ JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
124+ Q½= LeftIntegral (S,0.5 )
131125
132- y= (I+ Q½)\ 1
126+ y= (I+ Q½)\ 1
133127
134- x= Fun ()
135- @time @test norm (exp (1 + x)* erfc (sqrt (1 + x))- y) < 100 eps ()
128+ x= Fun ()
129+ @time @test norm (exp (1 + x)* erfc (sqrt (1 + x))- y) < 100 eps ()
136130
137- S= Legendre ()⊕ JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
138- x= Fun ()
139- Q½= LeftIntegral (S,0.5 )
131+ S= Legendre ()⊕ JacobiWeight (0.5 ,0. ,Ultraspherical (1 ))
132+ x= Fun ()
133+ Q½= LeftIntegral (S,0.5 )
140134
141- @time y= (I+ exp (- (1 + x)/ 2 )* Q½[exp ((1 + x)/ 2 )])\ exp (- (1 + x)/ 2 )
135+ @time y= (I+ exp (- (1 + x)/ 2 )* Q½[exp ((1 + x)/ 2 )])\ exp (- (1 + x)/ 2 )
142136
143- @test norm (y- exp ((1 + x)/ 2 )* erfc (sqrt (1 + x))) < 100 eps ()
137+ @test norm (y- exp ((1 + x)/ 2 )* erfc (sqrt (1 + x))) < 100 eps ()
138+ end
144139end
145140
146141end # module
0 commit comments