This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Periodic continued fraction expansions

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


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?