Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: How to do Continued fraction of polynomials

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53206] Re: [mg53052] How to do Continued fraction of polynomials
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Tue, 28 Dec 2004 23:12:43 -0500 (EST)
  • References: <200412220952.EAA04405@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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