       Re: Accuracy problem in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg49110] Re: Accuracy problem in Mathematica
• Date: Thu, 1 Jul 2004 05:26:09 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 6/30/04 at 5:34 AM, aaa at huji.ac.il (aaaa) 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.

>Can anybody help me?

The problem is setting a to 0.5. This causes Mathematica to use machine numbers for the entire computation. The solution is to increase the precision of a or to make it an exact value, i.e., either have a = 1/2 or a = N[1/2, m] for some reasonably large m

For example,

In:=
a = 1/2;
n = 400;
N[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}]]

Out=
0.05619267148769478

In:=
a = N[1/2, 100];
n = 400;
N[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}]]

Out=
0.05619267148769478
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: A question about derivatives of quadratic products
• Next by Date: Re: Accuracy problem in Mathematica
• Previous by thread: Re: Accuracy problem in Mathematica
• Next by thread: Re: Accuracy problem in Mathematica