Re: Continued Fraction Trouble

*To*: mathgroup at smc.vnet.net*Subject*: [mg111040] Re: Continued Fraction Trouble*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Sun, 18 Jul 2010 01:03:20 -0400 (EDT)

On my system, I do not get the behavior that you showed $Version 7.0 for Mac OS X x86 (64-bit) (February 19, 2009) quadcon[a_, c_, n_] :== FromContinuedFraction[Take[Flatten@ Table[{a c, a}, {1/8 (6 + 4 n)}], n]] data == Table[quadcon[1, -5, i], {i, 1, 200}]; N[data, 2] {-5.0,-4.0,-3.8,-3.7,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6,-3.6 ,! -3.6,-3.6} However, asking for low precision calculations is not conducive to good results. Recommend that you use NumberForm to control what is displayed NumberForm[data // N, {4, 1}] Bob Hanlon ---- Nicholas <physnick at gmail.com> wrote: ========================== I ran across an unexpected behavior of FromContinuedFraction that I hope someone can help me with. I originally thought is was a representation problem, but now I am not sure. When I was playing with the continued fraction solutions of a quadratic x^2 -a c x -c == 0, The continued fraction solution x == a c + 1/( a + 1/ ( a c + ... converges if the discriminant (a^2 c^2 + 4 c) is nonnegative. I tried to do this in Mathematica, using the function "quadcon" defined by quadcon[a_, c_, n_] :== FromContinuedFraction[ Take[Flatten@Table[{a c, a}, {1/8 (6 + 4 n)}], n]] which makes a list like {ac, a, ac, a, ac, a} that is then entered into FromContinuedFraction, but I got some weird results. For example, when I tried it with a==1, c ==-5, (which should converge), I get that it converges to the right value for the first 90 values of n, but then starts to wander around after that in fits of convergence: N[Table[quadcon[1, -5, i], {i, 1, 200}],2] {-5.0, -4.0, -3.8, -3.7, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -0.077, 1.3, 5.5, 30., -62., -30., -25., -23., -1.2*10^2, 2.0*10^2, 99., -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, -3.6, \ -3.6, -3.6, -3.6, -3.6, 2.1, 2.1, -0.16, 0.57, 5.9, 1.9, 17., 26., \ 23., 17., -29., -29., -34., -34., -23., -23., -22., -24., 1.9*10^2, 2.0*10^2} However, when I call quadcon with real numbers instead, I get the desired result for as long as I was patient enough to check. For example, N@Table[quadcon[1., -5., i], {i, 1, 20}] {-5., -4., -3.75, -3.66667, -3.63636, -3.625, -3.62069, -3.61905, \ -3.61842, -3.61818, -3.61809, -3.61806, -3.61804, -3.61804, -3.61804, \ -3.61803, -3.61803, -3.61803, -3.61803, -3.61803} ... This seems to happen when c is negative and the discriminant is positive. If the discriminant is zero (i.e. c==-1 or -4), Mathematica's continued fraction converges, and when a>0 and c>0, it also converges to the correct result. There are some theorems about convergence of quadratic continued fractions, but I have not tested these, and the problem persists if I use rational numbers as well, but I have not looked into it deeply. The problem seems to be averted if I plug in undetermined values into quadcon, then replace with numbers after, but I have not tested this extensively, and it is not reassuring. eg N@quadcon[-9., -5., 20] 44.8886 N@quadcon[-9, -5, 20] 1.26434 N@Simplify[quadcon[a, c, 20]] /. {a -> -9, c -> -5} 44.8886 What am I missing? -- Bob Hanlon