@@ -86,3 +86,30 @@ pS3 = Poly([1, 2, 3, 4, 5], :s)
86
86
@test_throws ErrorException pS1 * pX
87
87
@test_throws ErrorException pS1 / pX
88
88
@test_throws ErrorException pS1 % pX
89
+
90
+ # Tests for Pade approximants
91
+
92
+ println (" Test for the exponential function." )
93
+ a = Poly (1. // convert (Vector{Int},gamma (1 : 17 ))," x" )
94
+ PQexp = Pade (a,8 ,8 )
95
+ @test padeval (PQexp,1.0 ) == exp (1.0 )
96
+ @test padeval (PQexp,- 1.0 ) == exp (- 1.0 )
97
+
98
+ println (" Test for the sine function." )
99
+ b = Poly (convert (Vector{BigInt},sinpi ((0 : 16 )/ 2 )).// convert (Vector{BigInt},gamma (BigFloat (" 1.0" ): BigFloat (" 17.0" )))," x" )
100
+ PQsin = Pade (b,8 ,7 )
101
+ @test isapprox (padeval (PQsin,1.0 ),sin (1.0 ))
102
+ @test isapprox (padeval (PQsin,- 1.0 ),sin (- 1.0 ))
103
+
104
+ println (" Test for the cosine function." )
105
+ c = Poly (convert (Vector{BigInt},sinpi ((1 : 17 )/ 2 )).// convert (Vector{BigInt},gamma (BigFloat (" 1.0" ): BigFloat (" 17.0" )))," x" )
106
+ PQcos = Pade (c,8 ,8 )
107
+ @test isapprox (padeval (PQcos,1.0 ),cos (1.0 ))
108
+ @test isapprox (padeval (PQcos,- 1.0 ),cos (- 1.0 ))
109
+
110
+ println (" Test for the summation of a factorially divergent series." )
111
+ d = Poly (convert (Vector{BigInt},(- 1 ). ^ (0 : 60 ). * gamma (BigFloat (" 1.0" ): BigFloat (" 61.0" ))).// 1 ," x" )
112
+ PQexpint = Pade (d,30 ,30 )
113
+ println (" The approximate sum of the divergent series is: " ,float64 (padeval (PQexpint,1.0 )))
114
+ println (" The approximate sum of the convergent series is: " ,exp (1 )* (- γ- sum ([(- 1 ). ^ k/ k./ gamma (k+ 1 ) for k= 1 : 20 ])))
115
+ @test isapprox (padeval (PQexpint,1.0 ) , exp (1 )* (- γ- sum ([(- 1 ). ^ k/ k./ gamma (k+ 1 ) for k= 1 : 20 ])))
0 commit comments