Skip to content

cf2num

specfun · scripts/specfun/cf2num.m

: y = cf2num (a)
: [n, d] = cf2num (a)

Evaluate a simple continued fraction, or return its convergents.

a is a nonempty real vector of partial quotients [a0; a1, a2, …]. With one output, cf2num returns the numeric value of the finite continued fraction. With two outputs it returns the numerator and denominator vectors of every convergent (Wallis recurrence), each the same size as a, so n(k) ./ d(k) is the k-th convergent.

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

Behaviour note (MATLAB R2026a): MathWorks does not ship cf2num in R2026a. Nexus provides this name for next-wave math-012 (nexus#1861). For a = num2cf (pi, 4) the convergents are 3/1, 22/7, 333/106, 355/113.