commands → continuedfraction

continuedfraction(x)

The continuedfraction command takes a rational number x and returns a vector containing the expansion of x as a continued fraction. That is, it returns [a0,a1,a2,...] where x = a0 + 1/(a1 + 1/(a2 + ...)). The continuedfraction command can also compute the rational number described by a continued fraction expansion if a vector is input.

Examples

continuedfraction(314159/100000);
	[3, 7, 15, 1, 25, 1, 7, 4]

continuedfraction([3,7,15,1,25,1,7,4]);
	314159/100000;

continuedfraction([a0,a1,a2,a3,a4,a5]);
	a0+1/(a1+1/(a2+1/(a3+1/(a4+1/a5))))

Algorithm

The continued fraction representation of a rational number is obtained from the quotients in the Euclidean algorithm.

References

Gullberg, Jan. Mathematics: From the Birth of Numbers. Norton, 1996.