Re: Program to calculate rational function with imbedded continued fraction
- To: mathgroup at smc.vnet.net
- Subject: [mg69930] Re: [mg69875] Program to calculate rational function with imbedded continued fraction
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 27 Sep 2006 06:06:17 -0400 (EDT)
On 26 Sep 2006, at 18:21, Diana wrote: > Hello all, > > Would someone be able to help me write a program to calculate the > rational function of (2x + 3)/(2x + 4), for example? I have once already posted such a program and so did Daniel Lichtblau. (Search the archive for the subject "How to do Continued fraction of polynomials" and compare our posts. (I can't remember any more what the difference between them was). Here is my version: F[f_, g_] := If[PolynomialReduce[f, g][[1, 1]] =!= 0, PolynomialReduce[f, g][[ 1, 1]] + F[PolynomialReduce[f, g][[2]], g], Module[{u = g, v = f, p, ls}, ls = Flatten[Last[ Reap[While[u =!= 0, p = PolynomialReduce[u, v]; u = v; v = p[[2]]; Sow[ p[[1]]]]]]]; 1/Fold[Function[{x, y}, y + 1/x], Infinity, Reverse[ls]]]] In the case of your example above you need to evaluate: In[50]:= k=(2x+3)/(2x+4); In[51]:= F[Numerator[k],Denominator[k]] Out[51]= 1 + 1/(-2*x - 4) > > Also, (tx + 2t)(3t^2x + t), for example. What exactly do you mean? This does not make sense to me; is that a quotient? If so why did't you cancel the t's? I think the case of rational functions in several variables will be much harder, and I would have to think more about it, for which I do not have the time at this moment, and in any case it might not be what you are asking for. > > x is actually an infinite continued fraction, and I am trying to > figure > out how to divide one infinite continued fraction by another. > > (t [0, 1, 2, 1, 3, 1, 2, 1, 4, ...] + 2t)/(3t^2 [0, 1, 2, 1, 3, 1, 2, > 1, 4, ...] +t) > I think this can be done combining the built in function FromContinuedFraction with the function F defined above. Andrzej Kozlowski Tokyo, Japan