Periodic continued fraction expansions
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.
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)
The golden mean is famous for its simple continued fraction expansion:
numlib::contfracPeriodic(1/2, 1/2, 5)
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)
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 .