Function for arc cosine

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Function for arc cosine

Mahbub Khandoker
Hi there,
I was trying to calculate the distance between two postal codes by respective latitude and longitude data.
I use the following formula,

6370.997*arcos(sin(LAT1)*sin(LAT2) + cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))

But I couldn't find the function for "arcos" (arc cosine) from spss. I am using spss 15.0.

Could any one please let me know the spss function for arc cosine or any suitable formula to calculate distance between two Canadian postal codes?
Thanks,
Mahbub

Mahbub Khandoker
IT/DS Coordinator
IMG-Decision Support
Centre for Addiction and Mental Health
1001 Queen Street West
Toronto, ON, M6J 1H4
Tel: 416 535 8501 Ex 6534
Fax: 416 260 4154

This e-mail message is confidential and is intended only for the person(s) named above. Its contents may also be protected by privilege, and all rights to privilege are expressly claimed and not waived. If you have received this message in error, please notify the sender immediately and delete/remove it from your computer system. Any reading, distribution, printing or disclosure of this message if you are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Roberts, Michael
Arcosine is simply the inverse of the sine function. You could do
something to make the sine function work using this knowledge.
(1/sine(x)), etc.


Hth

mike


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Mahbub Khandoker
Sent: Wednesday, May 30, 2007 4:18 PM
To: [hidden email]
Subject: Function for arc cosine

Hi there,
I was trying to calculate the distance between two postal codes by
respective latitude and longitude data.
I use the following formula,

6370.997*arcos(sin(LAT1)*sin(LAT2) +
cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))

But I couldn't find the function for "arcos" (arc cosine) from spss. I
am using spss 15.0.

Could any one please let me know the spss function for arc cosine or any
suitable formula to calculate distance between two Canadian postal
codes?
Thanks,
Mahbub

Mahbub Khandoker
IT/DS Coordinator
IMG-Decision Support
Centre for Addiction and Mental Health
1001 Queen Street West
Toronto, ON, M6J 1H4
Tel: 416 535 8501 Ex 6534
Fax: 416 260 4154

This e-mail message is confidential and is intended only for the
person(s) named above. Its contents may also be protected by privilege,
and all rights to privilege are expressly claimed and not waived. If you
have received this message in error, please notify the sender
immediately and delete/remove it from your computer system. Any reading,
distribution, printing or disclosure of this message if you are not the
intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Peck, Jon
In reply to this post by Mahbub Khandoker
It is easy to extend SPSS transformations using the Python programmability plugin.  Here is a little example drawing on the acos function in the Python math module.  It assumes that x and y are the input variables and calculates a new variable named trigvar.  I didn't code the whole requested formula, but you would write additional terms in the obvious way and include the extra input variables in the def statement and the square bracketed list.

Besides the programmability plugin, this example uses the trans module from SPSS Developer Central (www.spss.com/devcentral).  That module packages up the tasks of defining new SPSS variables and running through the cases.

The Python math module has all the standard trig functions.  They expect their arguments in radians or return radians, and the math module includes a function named - you guessed it - radians that converts degrees to radians.

HTH,
Jon Peck


begin program.
import spss, trans
from math import sin, acos

def f(a,b):
  return 6370.997*acos(sin(a)*sin(b))

t = trans.Tfunction()
t.append(f, "trigvar", "f8.2", ["x", "y"])
t.execute()
end program.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mahbub Khandoker
Sent: Wednesday, May 30, 2007 3:18 PM
To: [hidden email]
Subject: [SPSSX-L] Function for arc cosine

Hi there,
I was trying to calculate the distance between two postal codes by respective latitude and longitude data.
I use the following formula,

6370.997*arcos(sin(LAT1)*sin(LAT2) + cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))

But I couldn't find the function for "arcos" (arc cosine) from spss. I am using spss 15.0.

Could any one please let me know the spss function for arc cosine or any suitable formula to calculate distance between two Canadian postal codes?
Thanks,
Mahbub

Mahbub Khandoker
IT/DS Coordinator
IMG-Decision Support
Centre for Addiction and Mental Health
1001 Queen Street West
Toronto, ON, M6J 1H4
Tel: 416 535 8501 Ex 6534
Fax: 416 260 4154

This e-mail message is confidential and is intended only for the person(s) named above. Its contents may also be protected by privilege, and all rights to privilege are expressly claimed and not waived. If you have received this message in error, please notify the sender immediately and delete/remove it from your computer system. Any reading, distribution, printing or disclosure of this message if you are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

David Greenberg
In reply to this post by Roberts, Michael
The arcsine is not 1 divided by the sine. It is the angle corresponding to a value of the sine. That is something quite different. David Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of
> Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I
> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or any
> suitable formula to calculate distance between two Canadian postal
> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by privilege,
> and all rights to privilege are expressly claimed and not waived. If you
> have received this message in error, please notify the sender
> immediately and delete/remove it from your computer system. Any reading,
> distribution, printing or disclosure of this message if you are not the
> intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Roberts, Michael
That is correct - hasty oversight - SPSS does not return the inverse of
the function by using the 1/(function).  However, SPSS has arsin and
artan as inverse functions for sin and tan, but none for cos(?)  Any
ideas?

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Greenberg
Sent: Wednesday, May 30, 2007 5:21 PM
To: [hidden email]
Subject: Re: Function for arc cosine

The arcsine is not 1 divided by the sine. It is the angle corresponding
to a value of the sine. That is something quite different. David
Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I

> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or
> any suitable formula to calculate distance between two Canadian postal

> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by
> privilege, and all rights to privilege are expressly claimed and not
> waived. If you have received this message in error, please notify the
> sender immediately and delete/remove it from your computer system. Any

> reading, distribution, printing or disclosure of this message if you
> are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Nagaraju Thogiti
Arcsin(x) +  arcsoc(x) = Pi/2.
Where X is in radians.

Thank you,
Nagu

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Roberts, Michael
Sent: Wednesday, May 30, 2007 2:31 PM
To: [hidden email]
Subject: Re: Function for arc cosine

That is correct - hasty oversight - SPSS does not return the inverse of
the function by using the 1/(function).  However, SPSS has arsin and
artan as inverse functions for sin and tan, but none for cos(?)  Any
ideas?

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Greenberg
Sent: Wednesday, May 30, 2007 5:21 PM
To: [hidden email]
Subject: Re: Function for arc cosine

The arcsine is not 1 divided by the sine. It is the angle corresponding
to a value of the sine. That is something quite different. David
Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I

> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or
> any suitable formula to calculate distance between two Canadian postal

> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by
> privilege, and all rights to privilege are expressly claimed and not
> waived. If you have received this message in error, please notify the
> sender immediately and delete/remove it from your computer system. Any

> reading, distribution, printing or disclosure of this message if you
> are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Nagaraju Thogiti
In reply to this post by Roberts, Michael
EDIT* formatting:

Arcsin(x) +  arccos(x) = Pi/2.
Where X is in radians.

-----Original Message-----
From: Nagaraju Thogiti
Sent: Wednesday, May 30, 2007 5:10 PM
To: 'Roberts, Michael'; [hidden email]
Subject: RE: Re: Function for arc cosine

Arcsin(x) +  arcsoc(x) = Pi/2.
Where X is in radians.

Thank you,
Nagu

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Roberts, Michael
Sent: Wednesday, May 30, 2007 2:31 PM
To: [hidden email]
Subject: Re: Function for arc cosine

That is correct - hasty oversight - SPSS does not return the inverse of
the function by using the 1/(function).  However, SPSS has arsin and
artan as inverse functions for sin and tan, but none for cos(?)  Any
ideas?

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Greenberg
Sent: Wednesday, May 30, 2007 5:21 PM
To: [hidden email]
Subject: Re: Function for arc cosine

The arcsine is not 1 divided by the sine. It is the angle corresponding
to a value of the sine. That is something quite different. David
Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I

> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or
> any suitable formula to calculate distance between two Canadian postal

> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by
> privilege, and all rights to privilege are expressly claimed and not
> waived. If you have received this message in error, please notify the
> sender immediately and delete/remove it from your computer system. Any

> reading, distribution, printing or disclosure of this message if you
> are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Richard Ristow
In reply to this post by Mahbub Khandoker
At 04:18 PM 5/30/2007, Mahbub Khandoker wrote:

>Hi there,
>I was trying to calculate the distance between two postal codes by
>respective latitude and longitude data.

Posted Thu, 3 Jul 2003 16:23:18 -0700 by Seumas Rogan
<[hidden email]> (I haven't checked the formula):

/*All x,y units are decimal degrees. All distances are statute miles.
/*WRR notes:
/*    Based on earth radius = 3,963 statute miles. For distances in
/*    other units, substitute the radius of the earth in those units.
/*  - Assumes that the trigonometric functions take, or return,
/*    angular values in radians (as SPSS trig functions do), and
/*    converts to or from decimal degrees accordingly
/*
/*1.Crude Distance
/*Approximate distance in miles = sqrt(x * x + y * y)
/*where x = 69.1 * (lat2 - lat1)
/*and y = 53 * (lon2 - lon1)
/*.

compute x2 = (69.1*(lat2-lat1))**2.
compute y2 = (53*(long2-long1))**2.
compute dcrude = sqrt(x2 + y2).

/*2. Better distance.
/*Approximate distance in miles = sqrt(x * x + y * y)
/*where x = 69.1 * (lat2 - lat1)
/*and y = 69.1 * (lon2 - lon1) * cos(lat1/57.3)
/*.

compute x2 = (69.1*(lat2-lat1))**2.
compute y2 = (69.1*(long2-long1)*cos(lat1/57.3))**2.
compute dmedium = sqrt(x2 + y2).

/*3a. Exact distance Radians
/*If you convert all latitude and longitude values in the database to
/*radians before the calculation, use this equation:
/*Exact distance in miles = 3963 * arccos[sin(lat1) *
/*sin(lat2) + cos(lat1) *
/*cos(lat2) * cos(lon2 - lon1)]
/*
/*To convert latitude or longitude from degrees to radians, divide the
/*latitude and longitude values in this database by 180/pi,
/*or 57.2958. The radius of the Earth is assumed to be 6,378
kilometers,
/*or 3,963 miles.

/*3b Exact distance decimal degrees.
/*
/*Exact distance in miles = 3963 * arccos[sin(lat1/57.2958) *
/*sin(lat2/57.2958) +
/*cos(lat1/57.2958) *
/*cos(lat2/57.2958) *
/*cos(lon2/57.2958 - lon1/57.2958)]
/*
/*OR
/*
/*
/*Distance = acos(sin(lat1)*sin(lat2)+cos(lat1)*
/*cos(lat2)*cos(long2-long1)) * r
/*
/*Where r is the radius of the earth in whatever units you desire.
/*r=3437.74677 (statute miles)
/*r=6378 (kilometers)
/*r=3963 (normal miles)
/*

compute d3 = 3963*arcos(sin(lat1/57.2958)*sin(lat2/57.2958) +
cos(lat1/57.2958)*cos(lat2/57.2958*cos(long2/57.2958-long1/57.2958)).
exe.

/*3c.
/*If the computer language you are using has no arccosine function, you
/*can calculate the same result using the arctangent function,
/*which most computer languages do support. Use the following equation:
/*
/*Exact distance in miles = 3958.75 * arctan[sqrt(1-x^2))/x]
/*
/*where x = [sin(lat1/57.2958) * sin(lat2/57.2958)] +
/*[cos(lat1/57.2958) *
/*cos(lat2/57.2958) *
/*cos(lon2/57.2958 - lon1/57.2958)]
/*.

compute x = (sin(lat1/57.2958)*sin(lat2/57.2958)) +
(cos(lat1/57.2958)*cos(lat2/57.2958)*cos(long2/57.2958-long1/57.2958)).
compute d_exact = 3958.75*artan((sqrt(1-(x*x)))/x).
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Nagaraju Thogiti
In reply to this post by Nagaraju Thogiti
Hi Mike,

I used SPSS 15.0 to test it. Here is the SPSS syntax I used:

IF (ABS(var1) <= 1) asin1 = ARSIN(var1) .
IF (ABS(var1) <= 1) acos1 = ARSIN(1.0) - ARSIN(var1) .
EXECUTE .


Thank you,
Nagu


-----Original Message-----
From: Roberts, Michael [mailto:[hidden email]]
Sent: Thursday, May 31, 2007 8:16 AM
To: Nagaraju Thogiti
Subject: RE: Re: Function for arc cosine

Hi Nagaraju,

Thank you for your response.  I have tried using the Arccos function
(using SPSS version 14.0.1) but it does not appear to be a valid
function(?). Any ideas? What version did you use to test this?

Thanks

Mike




-----Original Message-----
From: Nagaraju Thogiti [mailto:[hidden email]]
Sent: Wednesday, May 30, 2007 8:10 PM
To: Nagaraju Thogiti; Roberts, Michael; [hidden email]
Subject: RE: Re: Function for arc cosine

EDIT* formatting:

Arcsin(x) +  arccos(x) = Pi/2.
Where X is in radians.

-----Original Message-----
From: Nagaraju Thogiti
Sent: Wednesday, May 30, 2007 5:10 PM
To: 'Roberts, Michael'; [hidden email]
Subject: RE: Re: Function for arc cosine

Arcsin(x) +  arcsoc(x) = Pi/2.
Where X is in radians.

Thank you,
Nagu

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Roberts, Michael
Sent: Wednesday, May 30, 2007 2:31 PM
To: [hidden email]
Subject: Re: Function for arc cosine

That is correct - hasty oversight - SPSS does not return the inverse of
the function by using the 1/(function).  However, SPSS has arsin and
artan as inverse functions for sin and tan, but none for cos(?)  Any
ideas?

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Greenberg
Sent: Wednesday, May 30, 2007 5:21 PM
To: [hidden email]
Subject: Re: Function for arc cosine

The arcsine is not 1 divided by the sine. It is the angle corresponding
to a value of the sine. That is something quite different. David
Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I

> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or
> any suitable formula to calculate distance between two Canadian postal

> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by
> privilege, and all rights to privilege are expressly claimed and not
> waived. If you have received this message in error, please notify the
> sender immediately and delete/remove it from your computer system. Any

> reading, distribution, printing or disclosure of this message if you
> are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Nagaraju Thogiti
I looked at the SPSS command syntax reference, and didn't find any
existence of arcos function. If you insist on having a definition for
arcos, then you can define it as a function/macro.


-----Original Message-----
From: Roberts, Michael [mailto:[hidden email]]
Sent: Thursday, May 31, 2007 10:45 AM
To: Nagaraju Thogiti
Subject: RE: Re: Function for arc cosine

Hi Nagaraju,

Your code does not indicate use of the arccos function!  I know that
arsin and artan are existing functions, and can use them.  However,
arccos function does not appear to be available.  How do you get it to
work?

Thanks

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Nagaraju Thogiti
Sent: Thursday, May 31, 2007 12:56 PM
To: [hidden email]
Subject: Re: Function for arc cosine

Hi Mike,

I used SPSS 15.0 to test it. Here is the SPSS syntax I used:

IF (ABS(var1) <= 1) asin1 = ARSIN(var1) .
IF (ABS(var1) <= 1) acos1 = ARSIN(1.0) - ARSIN(var1) .
EXECUTE .


Thank you,
Nagu


-----Original Message-----
From: Roberts, Michael [mailto:[hidden email]]
Sent: Thursday, May 31, 2007 8:16 AM
To: Nagaraju Thogiti
Subject: RE: Re: Function for arc cosine

Hi Nagaraju,

Thank you for your response.  I have tried using the Arccos function
(using SPSS version 14.0.1) but it does not appear to be a valid
function(?). Any ideas? What version did you use to test this?

Thanks

Mike




-----Original Message-----
From: Nagaraju Thogiti [mailto:[hidden email]]
Sent: Wednesday, May 30, 2007 8:10 PM
To: Nagaraju Thogiti; Roberts, Michael; [hidden email]
Subject: RE: Re: Function for arc cosine

EDIT* formatting:

Arcsin(x) +  arccos(x) = Pi/2.
Where X is in radians.

-----Original Message-----
From: Nagaraju Thogiti
Sent: Wednesday, May 30, 2007 5:10 PM
To: 'Roberts, Michael'; [hidden email]
Subject: RE: Re: Function for arc cosine

Arcsin(x) +  arcsoc(x) = Pi/2.
Where X is in radians.

Thank you,
Nagu

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Roberts, Michael
Sent: Wednesday, May 30, 2007 2:31 PM
To: [hidden email]
Subject: Re: Function for arc cosine

That is correct - hasty oversight - SPSS does not return the inverse of
the function by using the 1/(function).  However, SPSS has arsin and
artan as inverse functions for sin and tan, but none for cos(?)  Any
ideas?

Mike




-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Greenberg
Sent: Wednesday, May 30, 2007 5:21 PM
To: [hidden email]
Subject: Re: Function for arc cosine

The arcsine is not 1 divided by the sine. It is the angle corresponding
to a value of the sine. That is something quite different. David
Greenberg, Sociology Department, New York University

----- Original Message -----
From: "Roberts, Michael" <[hidden email]>
Date: Wednesday, May 30, 2007 4:50 pm
Subject: Re: Function for arc cosine
To: [hidden email]


> Arcosine is simply the inverse of the sine function. You could do
> something to make the sine function work using this knowledge.
> (1/sine(x)), etc.
>
>
> Hth
>
> mike
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf
> Of Mahbub Khandoker
> Sent: Wednesday, May 30, 2007 4:18 PM
> To: [hidden email]
> Subject: Function for arc cosine
>
> Hi there,
> I was trying to calculate the distance between two postal codes by
> respective latitude and longitude data.
> I use the following formula,
>
> 6370.997*arcos(sin(LAT1)*sin(LAT2) +
> cos(LAT1)*cos(LAT2)*cos(LONG1-LONG2))
>
> But I couldn't find the function for "arcos" (arc cosine) from spss. I

> am using spss 15.0.
>
> Could any one please let me know the spss function for arc cosine or
> any suitable formula to calculate distance between two Canadian postal

> codes?
> Thanks,
> Mahbub
>
> Mahbub Khandoker
> IT/DS Coordinator
> IMG-Decision Support
> Centre for Addiction and Mental Health
> 1001 Queen Street West
> Toronto, ON, M6J 1H4
> Tel: 416 535 8501 Ex 6534
> Fax: 416 260 4154
>
> This e-mail message is confidential and is intended only for the
> person(s) named above. Its contents may also be protected by
> privilege, and all rights to privilege are expressly claimed and not
> waived. If you have received this message in error, please notify the
> sender immediately and delete/remove it from your computer system. Any

> reading, distribution, printing or disclosure of this message if you
> are not the intended recipient is strictly prohibited. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Richard Ristow
In reply to this post by Mahbub Khandoker
At 04:18 PM 5/30/2007, Mahbub Khandoker wrote:

>I couldn't find the function for "arcos" (arc cosine) from spss. I am
>using spss 15.0. I was trying to calculate the distance between two
>postal codes by respective latitude and longitude data.

Well, I still like Seumas Rogan's code, that I posted, with a complete
solution for distance by latitude-longitude. It could be cleaned up a
little for readability and versatility, but overall it's a first-rate
utility.

However, for arc cosine, we've been making it a lot harder than it is.
SPSS has had an ARSIN (arc sine) function since at least release 9.

arc cosine(X) = ARSIN(pi/2 - X).
Reply | Threaded
Open this post in threaded view
|

Re: Function for arc cosine

Peck, Jon
In the extendedTransforms module on SPSS Developer Central (www.spss.com/devcentral), there are two functions that implement distance calculations on Earth latitude and longitude coordinates.

sphDist:                       calculate distance between two points on earth using spherical approximation
ellipseDist:                  calculate distance between two points on earth using ellipsoidal approximation

The ellipsoidal calculation, which is quite a lot more complex, is somewhat more accurate, since the Earth is not a sphere.  (Well, it isn't exactly an ellipsoid either.)

Here is a simple usage example for just a single distance pair.
begin program.
import spss
import extendedTransforms

fromloc = (41.90, 87.65)
toloc = (41.73, 71.43)
dist1 = extendedTransforms.ellipseDist(fromloc[0], fromloc[1], toloc[0], toloc[1], inradians=False)
dist2 = extendedTransforms.sphDist(fromloc[0], fromloc[1], toloc[0], toloc[1], inradians=False)
print dist1, dist2
end program.

When inradians is False, the arguments are in degrees; if True, the arguments are in radians.

To give you an idea of the difference between these two functions, using the coordinates above (Chicago, IL to Providence, RI), the ellipsoidal and spherical results are

836.2705 and 834.0903 miles.

-Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow
Sent: Donnerstag, 7. Juni 2007 08:37
To: [hidden email]
Subject: Re: [SPSSX-L] Function for arc cosine

At 04:18 PM 5/30/2007, Mahbub Khandoker wrote:

>I couldn't find the function for "arcos" (arc cosine) from spss. I am
>using spss 15.0. I was trying to calculate the distance between two
>postal codes by respective latitude and longitude data.

Well, I still like Seumas Rogan's code, that I posted, with a complete
solution for distance by latitude-longitude. It could be cleaned up a
little for readability and versatility, but overall it's a first-rate
utility.

However, for arc cosine, we've been making it a lot harder than it is.
SPSS has had an ARSIN (arc sine) function since at least release 9.

arc cosine(X) = ARSIN(pi/2 - X).