MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to do Continued fraction of polynomials


Milind Gupta wrote:
> How can we do a continued fraction expansion in Mathematica.
> 
>    Suppose we have
>              x^3 + 2x
>              ------------
>               x^2 + 1
> 
> and we want:
> 
>      x  +       1
>              -------------
>               x   +    1
>                         ----
>                           x
> 
>      Can we get this by using some function or some technique in Mathematica??
> 
> Regards,

One method is to iterate taking a quotient and remainder, keeping the 
quotients and dividing previous remainders by new ones.

polynomialContinuedFraction[p1_,p2_,x_] := Module[{quot,rem,res},
   Reap[NestWhileList[
     ({quot,rem} = Developer`PolynomialDivision[#[[1]],#[[2]],x];
     Sow[quot,res];
     {#[[2]],rem})&,
     {p1,p2},
     !Developer`ZeroQ[#[[2]]]&]][[2,1]]
   ]

For your example:

In[12]:= convergents = polynomialContinuedFraction[x^3+2*x, x^2+1, x]
Out[12]= {x, x, x}

To change to the customary format you can use

pcfForm[{l1_}] := l1
pcfForm[ll_List] := First[ll] + 1/pcfForm[Rest[ll]]

In[16]:= InputForm[pcfForm[convergents]]
Out[16]//InputForm= x + (x^(-1) + x)^(-1)


Daniel Lichtblau
Wolfram Research




  • Prev by Date: Re: including files
  • Next by Date: Re: including files
  • Previous by thread: How to do Continued fraction of polynomials
  • Next by thread: Re: How to do Continued fraction of polynomials