Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

awk and trig functions

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-03-2009
pauli pauli is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 23 September 2012, 7:52 AM EDT
Location: Singapore
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Bug awk and trig functions

dear all,

In my script, it would be ideal if I could use an arc-cos (inverse cos) function. I think trig functions are indeed provided by awk, but not inverse trig functions.

So my question simply is: are there any alternative ways to incorporate inverse trig functions into a script?

Any help greatly appreciated!

Many thanks,

pauli
Sponsored Links
    #2  
Old Unix and Linux 07-03-2009
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 6 December 2016, 4:45 PM EST
Location: Foxborough, MA
Posts: 7,988
Thanks: 195
Thanked 698 Times in 654 Posts
look here or here or here

Code:
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) }


Last edited by vgersh99; 07-03-2009 at 09:47 AM..
Sponsored Links
    #3  
Old Unix and Linux 07-15-2009
ubeejani ubeejani is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 15 September 2009, 6:52 AM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,
I want to calculate distance between two GPS coordinates(Latitude A, Longitude A, Latitude B, Longitude B). By Spherical Law, the formula is:
distance= ACOS ( SIN(latA) * SIN(latB) + COS(latA) * COS(latB) * COS(longB-LongA)) * R
where R= Radius of the earth(6371)
As there is no ACOS function in awk, therefore I have to use the following method:
function acos(x) { return atan2(sqrt(1-x*x), x) }
value = sin(latA) * sin(latB) + cos(latA) * cos(latB) * cos(longB-LongA)
distance = acos(value)*R
But I don't know when I calculate the distance using this method, I get different value from Spherical law formula. For Spherical Law I use MS Excel to calculate the value.
I need your help please.Thanks a lot.
Regards,
Ubee
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
functions TimHortons Shell Programming and Scripting 2 04-08-2009 11:41 AM
Use of functions amitrajvarma Shell Programming and Scripting 1 11-23-2007 06:52 AM
ksh functions scriptingmani Shell Programming and Scripting 3 07-06-2007 08:15 AM
functions in Raom Shell Programming and Scripting 6 07-21-2006 04:06 AM
Regarding functions sendhilmani Shell Programming and Scripting 2 03-24-2006 04:40 AM



All times are GMT -4. The time now is 10:22 AM.