[metapost] Metafun : is "atan" the arctangent function?

Franck Pastor franck.pastor at me.com
Sun Jan 12 23:08:54 CET 2014


Le 12 janv. 2014 à 20:30, John Kitzmiller a écrit :

> On Jan 12, 2014, at 2:02 PM, "Daniel H. Luecking" <luecking at uark.edu> wrote:
> 
>> On Jan 12, 2014, at 9:32am, jkitzm wrote:
>> 
>>> atan is vardef'd in mp-tool.mpiv as:   x-(x**3)/3+(x**5)/5-(x**7)/7 , 
>>> part of the infinite series form. Maybe better to use asin(a/sqrt(a**2+1))?
>> 
>> The functions asin and acos are similarly defined in mp-tool: 
>> 
>>  vardef asin primary x = (x+(x**3)/6+3(x**5)/40)  enddef ;
>>  vardef acos primary x = (asin(-x))                      enddef ;
>> 
>> (That second one is just wrong, it should be (90-asin(x)).)
>> But those functions are redefined a few lines later using "angle": 
>> 
>>  vardef asin   primary x = angle((1+-+x,x)) enddef ;
>>  vardef acos  primary x = angle((x,1+-+x)) enddef ;
>> 
>> It is unclear why only atan was left with its bad definition. 
>> This is clearly a bug.
>> 
>> Note that the asin and acos functions return degrees. The file 
>> mp-tool.mpiv also also defines the alternatives invsin and 
>> invcos, which return radians. 
> 
> On Jan 12, 2014, at 12:25 PM, Dirk Laurie <dirk.laurie at gmail.com> wrote:
> 
>> Or use the builtin `angle`.
>> 
>> $ mf null
>> This is METAFONT, Version 2.718281 (TeX Live 2012)
>> (/usr1/local/texlive/2012/texmf-dist/metafont/base/null.mf)
>> 
>> * Pi=3.141592653589793;
>> 
>> * vardef atan(expr t) = angle(1,t)*Pi/180 enddef;
>> 
>> * show atan(1);
>>>> 0.7854
>>> 
> 
> I was attracted to the elegance of Dirk's solution, but it looks like the precision of both of our solutions varies? (Using my old HP calculator as the standard…maybe weak.) And Dan is right, the definitions are inconsistent.

Comparing your solution and the solution of Dirk (and this of grafbase.mp — maintained by Dan — which is almost the same and gives the same result), it seems that the latter is more accurate. 

Your formula gives:

atan(1) =  0.78552
atan(sqrt(3)) = 1.04738
atan(sqrt(3)/3) = 0.52368

whereas Dirk's definition returns:

atan(1)=0.7854
atan(sqrt(3)) = 1.0472
atan(sqrt(3)/3) = 0.52359

The exact values and their accurate approximations given by my Casio Graph 25+ calculator:

atan(1) = pi/4 \approx 0.7853981634
atan(sqrt(3)) = pi/3 \approx 1.047197551
atan(sqrt(3)/3) = pi/6 \approx 0.5235987756

In each of these three examples Dirk's and Dan's definitions win the contest… But I'm not able to explain why.

> 
> If we can get this sorted out should we go over to the Contextgarden and have Hans et al fix it in the next beta?

Hans Hagen is on this mailing list, so I suppose it's not necessary (but why not?).








More information about the metapost mailing list