Atan2 function in awk

Hello All,

I need your help in the following situation. I have a 100x100 matrix with angle values ranging from -180 to 180. I would like to calculate the atan2 values for the above mentioned matrix, and the output should be in the same format (100x100 matrix).

I tried the following code:

awk '{for(i=1; i<=NF; i++) {s=s FS atan2($i)} print s;s=""}' input > output

But, I got the following error:

^1 is invalid as number of arguments for atan2

Could anyone help me in this regard? Expecting your replies and thanks in advance.

Warm regards
Fredrick.

atan requires two arguments.

atan2(y, x)
  This gives you the arctangent of y / x in radians.

Hi Scott,

Thanks for your reply. As I am having my input as angles in the range of -180 to 180 in degrees, how can I convert this angle in to x and y? Since atan2() function will be taken in the form of atan2(y,x) or other forms with x and y.

So could you help me in this regard. Thanks in advance.

Warm regards
Fredrick.

You are on the wrong track. atan is the arctangens. For angles, you can calculate tan (alpha). atan is the inverse, yielding an angle as a result.

Go back to high school maths: tan (alpha) = sin (alpha) / cos (alpha).