Convergent

Author

Eric W. Weisstein
November 28, 2003

This notebook downloaded from http://mathworld.wolfram.com/notebooks/NumberTheory/Convergent.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Convergent.html.

©2005 Wolfram Research, Inc. except for portions noted otherwise

Code

ConvergentArrayDense[a_List]:=Module[{m=DiagonalMatrix[a],n=Length[a],i},
Do[
m[[i+1,i]]=1;
m[[i,i+1]]=-1,
{i,n-1}];
m
]

ConvergentArraySparse[a_List]:=Module[{n=Length[a]},SparseArray[{
Table[{i,i},{i,n}]->a,
{i_,j_}/; i==j+1->1,
{i_,j_}/;j==i+1->-1
},
{n,n}]
]

Convergent[a_List]:=Module[{l=ConvergentArraySparse[a]},
Det[l]/Det[Rest[Rest/@l]]
]

Convergents[c_,n_]:=Table[FromContinuedFraction[ContinuedFraction[c,k]],{k,n}]

Examples

ContinuedFraction[Pi,3]

ConvergentArrayDense[{3,7,15}]

((Det[(({{3, -1, 0}, {1, 7, -1}, {0, 1, 15}}))])/(Det[(({{7, -1}, {1, 15}}))]))

Convergent[ContinuedFraction[Pi,3]]

FromContinuedFraction[ContinuedFraction[Pi,3]]