Inverse trigonometric functions in awk

Quote:

>do asin, acos exist in awk,gawk or nawk?

>from internet search I would have thought they would.

>But they don't seem to exist when i try to use them.

> when I type

>awk '{print acos($1) ,$2}' effarea.dat

>I get the message:

>awk: cmd. line:1: (FILENAME=effarea.dat FNR=1) fatal: function `acos'

>not defined

>same thing happened when I used nawk or gawk.

>Is there a way to do this?

Use mathematical identities such as:

(sin a)**2 + (cos a)**2 = 1

tan a = (sin a)/(cos a)

so with a value v that is the cosine of an angle a,

tan(a) = sin(a)/cos(a) = sqrt(1 - (v)*(v))/(v)

tan(a) = sqrt((1/(v*v)) - 1)

a = atan2(sqrt(1/(v*v)) -1)

you can so the same thing starting with sine instead of cosine

Make sure you don't divide by zero. :-)

Chuck Demas

--

Eat Healthy | _ _ | Nothing would be done at all,

Die Anyway | v | That no one could find fault with it.