Inverse trigonometric functions in awk 
Author Message
 Inverse trigonometric functions in awk

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?
Melroy



Mon, 19 Dec 2005 04:57:09 GMT  
 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.



Mon, 19 Dec 2005 06:41:50 GMT  
 Inverse trigonometric functions in awk

Quote:

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

No. They are easily defined, however:

function asin(x) { return atan2(x, sqrt(1-x*x)) }
function acos(x) { return atan2(sqrt(1-x*x), x) }
function atan(x) { return atan2(x,1) }

Beware of rounding errors with arguments close to 1.

--
Tapani Tarvainen



Mon, 19 Dec 2005 15:52:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Trigonometric functions

2. Trigonometric functions in JavaScript

3. trigonometric functions....

4. trigonometric functions in vhdl??

5. Trigonometric functions in ASM

6. trigonometric functions

7. trigonometric function errors

8. trigonometric functions problems

9. name for functions that are their own inverse

10. Fix to complex, inverse-trig functions

11. Anyone have an inverse erf function VI?

12. Matrix Inverse Function

 

 
Powered by phpBB® Forum Software