Skip to content

num2cf

specfun · scripts/specfun/num2cf.m

: a = num2cf (x)
: a = num2cf (x, n)

Continued-fraction coefficients of the real scalar x.

Returns the simple continued-fraction partial quotients [a0; a1, a2, …] as a row vector, using the floor map a_k = floor(r_k), r_{k+1} = 1/(r_k - a_k). With one argument at most 20 terms are produced (stopping early when the remainder is exact). With n, at most n terms are returned.

Output class is single when x is single, otherwise double.

Behaviour note (MATLAB R2026a): MathWorks does not ship num2cf in R2026a (which / help miss; absent from toolbox/matlab/specfun and elfun). Nexus provides this name for next-wave math-012 (nexus#1861). Golden check: the first four coefficients of pi are [3, 7, 15, 1], whose convergents include 22/7 and 355/113.