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 nonperiodic part,
the second one contains the periodic part of the expansion.
The nonperiodic part may be an empty list. No periodic part
is returned for rational input, i.e., q =
0 or n
square.
The nonperiodic 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)

A rational number 

A rational number 

A positive integer 
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 .