Continued Fractions - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 16 : Continued Fractions

Enhancements to Continued Fractions in Maple 16

A continued fraction is a mathematical expression of the form b0+a1b1+a2b2+a3b3+a4b4+ approximating either a constant or a function. Continued fractions are well known to provide very good rational approximations, as demonstrated in the following examples.

 

Example 1: Approximating π by rational numbers

Example 2: Approximating tanx by a rational function

Periodic continued fractions

Example 1: Approximating π by rational numbers

 

The following command computes the continued fraction approximation to π of order 10.

withnumtheory:

cfracπ

3+17+115+11+1292+11+11+11+12+11+13+...

(1)

In this case, all "numerators" ai are 1, and all "denominators" bi are positive. The successive convergents c1=3, c2=3+17, c3=3+17+115, c4=3+17+115+11, c5=3+17+115+11+1292,  of this continued fraction are finite continued fractions, namely rational numbers, giving better and better numerical approximations of π. They can be computed by specifying optional arguments:

cfracπ,10,'c':

c

3,227,333106,355113,10399333102,10434833215,20834166317,31268999532,833719265381,1146408364913,42729431360120,...

(2)

evalf20c

3.,3.1428571428571428571,3.1415094339622641509,3.1415929203539823009,3.1415926530119026041,3.1415926539214210447,3.1415926534674367055,3.1415926536189366234,3.1415926535810777712,3.1415926535914039785,3.1415926535893891715,...

(3)

abserror  mapzevalf20πz, c1..10

abserror:=0.1415926535897932385,0.0012644892673496186,0.0000832196275290876,2.66764189062410-7,5.77890634410-10,3.31627806210-10,1.22356533010-10,2.9143384910-11,8.715467310-12,1.610740010-12

(4)

You can see that the well-known rational approximation π227 occurs as the second convergent c2, and it is accurate to 2 decimal digits after the decimal point.

The best approximations, however, are obtained from the centered continued fraction, which allows "denominators" to be negative as well:

cfracπ,10,'c',centered

3+17+1161294131415115+1312+12+...

(5)

The ability to obtain the convergents for a centered continued fraction with an optional argument was added in Maple 16.

c

3,227,355113,10434833215,31268999532,1146408364913,54193511725033,8014385725510582,24585092278256779,411557987131002976,1068966896340262731,...

(6)

evalf20c

3.,3.1428571428571428571,3.1415929203539823009,3.1415926539214210447,3.1415926536189366234,3.1415926535914039785,3.1415926535898153832,3.1415926535897926594,3.1415926535897931603,3.1415926535897932578,3.1415926535897932354,...

(7)

abserror  mapzevalf20πz, c1..10

abserror:=0.1415926535897932385,0.0012644892673496186,2.66764189062410-7,3.31627806210-10,2.9143384910-11,1.610740010-12,2.2144710-14,5.79110-16,7.8210-17,1.9310-17

(8)

 

Example 2: Approximating tanx by a rational function

 

In this example, a continued fraction approximation of order 10 to the tangent function around x=0 is computed:

cfractanx

x1x23x25x27x29x211x213x215x217x219+...

(9)

In this example, all the "numerators" are powers of x (up to sign), and the "denominators" exhibit an obvious pattern. Again, the convergents c1=x1, c2=x1x23, c3=x1x23x25, c4=x1x23x25x27,  form approximations of tanx of higher and higher orders. In this case, we obtain the convergents by calling cfrac twice, since applying cfrac to a continued fraction returns the rational function (or rational number) it represents:

cfractanx,1

x1+...

(10)

c1cfrac

c1:=x

(11)

cfractanx,2

x1x23+...

(12)

c2cfrac

c2:=3x3+x2

(13)

c3cfraccfractanx,3

c3:=13x15+x25+2x2

(14)

c4cfraccfractanx,4

c4:=5x21+2x210545x2+x4

(15)

c5cfraccfractanx,5

c5:=115x945105x2+x46328x2+x4

(16)

for i from 1 to 5 do   seriesOtanxci,x,20 end;

Ox3

Ox5

Ox7

Ox9

Ox11

(17)

In fact, the convergents provide better approximations to then tangent function around x=0 than the Taylor expansion of the same order. Below, this is illustrated for c5 and the Taylor expansion s to tanx with the same error term, Ox11, by plotting the two differences tanxs and tanxc5:

seriestanx,x,11

x+13x3+215x5+17315x7+622835x9+Ox11

(18)

sconvert,polynom

s:=x+13x3+215x5+17315x7+622835x9

(19)

plottanxs,tanxc5,x=1..1, legend=Taylor,continued fraction,thickness=2,color=red,blue

For example, the absolute errors for the two approximations at x=1 are:

evalftanxsx=a|f(x)x=1

0.014903316

(20)

evalftanxc5x=a|f(x)x=1

3.1810-7

(21)

The ability to compute a continued fraction at an expansion point other than 0 was added in Maple 16:

cfractanx,x=π

xπ1xπ23xπ25xπ27xπ29+...

(22)

 

Periodic continued fractions

 

Any rational number has a finite, and therefore periodic, continued fraction. It is a classical fact that more generally a real number has a periodic continued fraction expansion if and only if it is either rational or a real algebraic number of degree 2, i.e., a number of the form a+bd, where a and b are rational numbers and d is a positive integer. For example, the periodic continued fraction expansion for 7 is:

cfrac7,periodic

2+11+11+11+14+11+11+11+14+...

(23)

Maple's data structure for periodic continued fractions has two components: a list of integers representing the preperiod, and another list of positive integers denoting the repeating period. This representation can be requested using an optional argument:

cfrac7,periodic,quotients

2,1,1,1,4

(24)

As of Maple 16, applying the cfrac command to such a list will return the real number represented by that continued fraction. For example, the following command finds the quadratic irrational number whose continued fraction expansion is an infinite repetition of the period 1+12+13+14+15:

cfrac,1,2,3,4,5

131465029+195314

(25)

cfrac,periodic

1+12+13+14+15+11+12+13+14+15+...

(26)

cfrac,20

1+12+13+14+15+11+12+13+14+15+11+12+13+14+15+11+12+13+14+15+11+...

(27)