Arithmetic-Geometric Mean confusion



On 6/12/10 2:17 AM, Je Suis wrote:
>> We can work around some of the problems and produce an answer close to
>> what Mathematica produces by using bfloats.
>>
>> fpprec:32;
>> x=1;
>> y=1b-15;
>> elliptic_kc(((x-y)/(x+y))^2);
>>
>> 17.9265353780153059...
>>
>> Ray
> 
>  I suspected that to be the problem when I tried Scilab and saw the truncated results. I tried "fpprec" but with "1e-15", not "1b-15", hence the difference that lead me to that conclusion.
>  The numbers are needed for the current work and they're the worst case scenario; I didn't choose them for a willing head-ache :)

No problem.

If you are going to be using values like x=1 and y small, you might want
to compute ((x-y)/(x+y))^2 in a better way.   Just rewrite (x-y)/(x+y)
as 1-2*y/(x+y).  Since you're squaring it, then use
1-4*y/(x+y)+(2*y)^2/(x+y)^2.  This gives a little bit of extra accuracy
that might be important.

In fact, for x=1, y=1e-15 (not bfloat!) I find that elliptic_kc =
17.962.  Better than before, but not quite as good as the bfloat version.

Ray