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
The following command computes the continued fraction approximation to π of order 10.
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:
abserror ≔ mapz→evalf20π−z, c1..10
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:
The ability to obtain the convergents for a centered continued fraction with an optional argument was added in Maple 16.
abserror ≔ mapz→evalf20π−z, c1..10
In this example, a continued fraction approximation of order 10 to the tangent function around x=0 is computed:
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=x1−x23, c3=x1−x23−x25, c4=x1−x23−x25−x27, … 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:
for i from 1 to 5 do seriesOtanx−ci,x,20 end;
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 tanx−s and tanx−c5:
plottanx−s,tanx−c5,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:
The ability to compute a continued fraction at an expansion point other than 0 was added in Maple 16:
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:
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:
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:
Download Help Document
What kind of issue would you like to report? (Optional)