COS Functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was wondering if there is an equivalant function to ACOS in Access, the
function is available in VBA for Excel but I cannot find it in Access, I know
it has COS, Tan and Sin but I really need th ACOS function
 
Paste the functions below into a module (click New on the Modules tab of
Database Window). You can then use them like the built-in functions.

(These come from an old sample database Microsoft released years ago, named
neatcode.mdb.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Nigel said:
I was wondering if there is an equivalant function to ACOS in Access, the
function is available in VBA for Excel but I cannot find it in Access, I
know
it has COS, Tan and Sin but I really need th ACOS function



Function ArcCos(X As Double) As Double
' Inverse Cosine
If X = 1 Then
ArcCos = 0
ElseIf X = -1 Then
ArcCos = -PI()
Else
ArcCos = Atn(X / Sqr(-X * X + 1)) + PI() / 2
End If
End Function

Function Arccosec(X As Double) As Double
' Inverse Cosecant
Arccosec = Atn(X / Sqr(X * X - 1)) + (Sgn(X) - 1) * PI() / 2
End Function

Function Arccotan(X As Double) As Double
' Inverse Cotangent
Arccotan = Atn(X) + PI() / 2
End Function

Function ArcSec(X As Double) As Double
' Inverse Secant
ArcSec = Atn(X / Sqr(X * X - 1)) + Sgn(Sgn(X) - 1) * PI() / 2
End Function

Function ArcSin(X As Double) As Double
' Inverse Sine
If X = 1 Then
ArcSin = PI() / 2
ElseIf X = -1 Then
ArcSin = -PI() / 2
Else
ArcSin = Atn(X / Sqr(-X * X + 1))
End If
End Function

Function ATan2(X As Double, Y As Double) As Double
'
' Returns the ArcTangent based on X and Y coordinates
' If both X and Y are zero an error will occur.
'
' The positive X axis is assumed to be 0, going poistive in the
' counterclockwise direction, and negative in the clockwise direction.
'
If X = 0 Then
If Y = 0 Then
ATan2 = 1 / 0
ElseIf Y > 0 Then
ATan2 = PI() / 2
Else
ATan2 = -PI() / 2
End If
ElseIf X > 0 Then
If Y = 0 Then
ATan2 = 0
Else
ATan2 = Atn(Y / X)
End If
Else
If Y = 0 Then
ATan2 = PI()
Else
ATan2 = (PI() - Atn(Abs(Y) / Abs(X))) * Sgn(Y)
End If
End If
End Function

Function Cosec(X As Double) As Double
' Cosecant
Cosec = 1 / Sin(X)
End Function

Function Cotan(X As Double) As Double
' Cotangent
Cotan = 1 / Tan(X)
End Function

Function Deg2Rad(X As Double) As Double
' Degrees to radians
Deg2Rad = X / 180 * PI()
End Function

Function HArccos(X As Double) As Double
' Inverse Hyperbolic Cosine
HArccos = Log(X + Sqr(X * X - 1))
End Function

Function HArccosec(X As Double) As Double
' Inverse Hyperbolic Cosecant
HArccosec = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)
End Function

Function HArccotan(X As Double) As Double
' Inverse Hyperbolic Tangent
HArccotan = Log((X + 1) / (X - 1)) / 2
End Function

Function HArcsec(X As Double) As Double
' Inverse Hyperbolic Secant
HArcsec = Log((Sqr(-X * X + 1) + 1) / X)
End Function

Function HArcsin(X As Double) As Double
' Inverse Hyperbolic Sine
HArcsin = Log(X + Sqr(X * X + 1))
End Function

Function HArctan(X As Double) As Double
' Inverse Hyperbolic Tangent
HArctan = Log((1 + X) / (1 - X)) / 2
End Function

Function HCos(X As Double) As Double
' Hyperbolic Cosine
HCos = (Exp(X) + Exp(-X)) / 2
End Function

Function HCosec(X As Double) As Double
' Hyperbolic Cosecant = 1/HSin(X)
HCosec = 2 / (Exp(X) - Exp(-X))
End Function

Function HCotan(X As Double) As Double
' Hyperbolic Cotangent = 1/HTan(X)
HCotan = (Exp(X) + Exp(-X)) / (Exp(X) - Exp(-X))
End Function

Function HSec(X As Double) As Double
' Hyperbolic Secant = 1/HCos(X)
HSec = 2 / (Exp(X) + Exp(-X))
End Function

Function HSin(X As Double) As Double
' Hyperbolic Sine
HSin = (Exp(X) - Exp(-X)) / 2
End Function

Function HTan(X As Double) As Double
' Hyperbolic Tangent = HSin(X)/HCos(X)
HTan = (Exp(X) - Exp(-X)) / (Exp(X) + Exp(-X))
End Function

Function PI() As Double
PI = Atn(1) * 4
End Function

Function Rad2Deg(X As Double) As Double
' Radians to Degrees
Rad2Deg = X / PI() * 180
End Function

Function Sec(X As Double) As Double
' Secant
' This will choke at PI/2 and 3PI/2 radians (90 & 270 degrees)
'
Sec = 1# / Cos(X)
End Function
 
Here is the function in excel

=ACOS(COS(Z15-Z14)-SIN(Z14)*SIN(Z15)*(1-COS(AA15-AA14)))

and the result returned is 0.01

here is the function in access

Me!Excelab = ArcCos(Cos(Excelz - excelz1) - Sin(excelz1) * Sin(Excelz) * (1
- Cos(Excelaa - excelaa1)))

z1 and aa1 are z14 and aa14 (Previous record values)

here are the values in each cell

z14 (excelz1) =0
aa14 (excelaa1)= 0
z15 (excelz) =0.01
aa15 (excelaa) =5.18


and the result returned is 3.13

The code that you sent is really good but I could not find the function
ACOS, I see there is an ATAN function but not ACOS


if I remove the ACOS function in the excel spreadsheet then both
calculations are correct
Any help is appreciated as arcCos appears to not be the same as ACOS

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top