Re: Accuracy problem in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg49093] Re: Accuracy problem in Mathematica
- From: bobhanlon at aol.com (Bob Hanlon)
- Date: Thu, 1 Jul 2004 05:25:38 -0400 (EDT)
- References: <cbu21o$5ea$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
f1[a_, n_] := Evaluate[1/(1-a^2)^n+ Sum[((2*n-k-1)!/((n-1)!*(n-k)!*2^(2*n-k)))*(1/(1+a)^k-1/(1-a)^k),{k,1, n}]]; f1[a,n] (1 - a^2)^(-n) - (2^(1 - 2*n)*Pi*Csc[2*n*Pi]* (a*HypergeometricPFQRegularized[{1, 1 - n}, {2 - 2*n}, -(2/(a - 1))] + HypergeometricPFQRegularized[{1, 1 - n}, {2 - 2*n}, -(2/(a - 1))] + a*HypergeometricPFQRegularized[ {1, 1 - n}, {2 - 2*n}, 2/(a + 1)] - HypergeometricPFQRegularized[{1, 1 - n}, {2 - 2*n}, 2/(a + 1)]))/((a - 1)*(a + 1)*(n - 1)!*Gamma[n]) Note that this expression cannot be evaluated directly for integer values of n. A limit is required lim=Limit[f1[a,n], n->4] (5*a^3 + 20*a^2 + 29*a + 16)/(16*(a + 1)^4) However by reversing the order of the summation a more useful form is available f2[a_, n_] := Evaluate[FullSimplify[ 1/(1-a^2)^n+ Sum[((2*n-k-1)!/((n-1)!*(n-k)!*2^(2*n-k)))*(1/(1+a)^k-1/(1-a)^k),{k, n,1,-1}], Element[n, Integers]]]; f2[a,n] (1 - a^2)^(-n) + (Gamma[n + 1/2]* (Hypergeometric2F1Regularized[1, 2*n, n + 1, (1 - a)/2] - Hypergeometric2F1Regularized[1, 2*n, n + 1, (a + 1)/2]))/(2*Sqrt[Pi]) f2[a,4]==lim // Simplify True For more precise calculations you must use a more precise number for a, i.e., rationalize a Table[{2^k,N[f2[1/2,2^k]]},{k,10}] {{2, 0.5555555555555556}, {4, 0.44598765432098764}, {8, 0.3456065255391709}, {16, 0.25973818180857106}, {32, 0.19065663499323857}, {64, 0.13772351481722211}, {128, 0.09851761077419757}, {256, 0.07008483104129602}, {512, 0.049711093180366435}, {1024, 0.03520617306671809}} Bob Hanlon In article <cbu21o$5ea$1 at smc.vnet.net>, "aaaa" <aaa at huji.ac.il> wrote: << I'm having a problem with a calculation in Mathematica which I can't solve. I have an expression which I know to be (from analytical reasons) always between 0 and 1. It's a function of a and n ( n being natural and a rational) and it looks like this: 1/(1-a^2)^n + Sum[((2*n - k - 1)!/((n - 1)!*(n - k)!*2^(2*n - k)))*(1/(1 + a)^k - 1/(1 - a)^k), {k, 1, n}] Let's say a=0.5. Now, when I try to calculate for small n, it's ok. When calculating for large n's (around 400 and above) I'm starting to get wrong results (the number not being between 0 and 1). The problem is that the first term (the first line before the sum) is VERY VERY close to the negative of the second term (the sum), and it's getting closer as n grows. When using large n's, Mathematica says they are the same number or even that the last term is bigger (which means the whole expression becomes negative) - which is wrong. It's a matter of accuracy, and I'm not sure how I can fix it. >><BR><BR>