Periodic continued fraction expansions

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.


numlib::contfracPeriodic(p, q, n)


numlib::contfracPeriodic(p, q, n) returns the continued fraction expansion of p + q*sqrt(n) as a sequence of two lists: the first one contains the non-periodic part, the second one contains the periodic part of the expansion.

The non-periodic part may be an empty list. No periodic part is returned for rational input, i.e., q = 0 or n square.


Example 1

The non-periodic part may start with zero. All other coefficients of a continued fraction expansion are positive:

numlib::contfracPeriodic(2/7, 1/7, 2)

The result agrees with that one of contfrac:

op(contfrac(2/7 + 1/7 *sqrt(2)), 1)

Example 2

The golden mean is famous for its simple continued fraction expansion:

numlib::contfracPeriodic(1/2, 1/2, 5)

Example 3

Since 81 is a perfect square, there is no periodic part in the continued fraction expansion of its square root:

numlib::contfracPeriodic(0, 1, 81)



A rational number


A rational number


A positive integer

Return Values

If is a rational number, then numlib::contfracPeriodic returns one list, otherwise two lists of integers.


A real number has a periodic continued fraction expansion if and only if it is of the form .

See Also

MuPAD Functions

Was this topic helpful?