Code - Math - Trigonometry
Circular Functions
Both ASP and PHP contain the three basic trigonometry functions: sine, cosine, and tangent. There are three more basic trigonometry functions: cosecant, secant, and cotangent.
Cosecant
| ASP |
PHP |
function csc(x)
csc = 1 / sin(x)
end function
|
function csc($x)
{
return (1 / sin($x));
}
|
Secant
| ASP |
PHP |
function sec(x)
sec = 1 / cos(x)
end function
|
function sec($x)
{
return (1 / cos($x));
}
|
Cotangent
| ASP |
PHP |
function cot(x)
cot = 1 / tan(x)
end function
|
function cot($x)
{
return (1 / tan($x));
}
|
Besides the basic trigonmetric functions, there are some special functions which are rarely used anymore: versed sine, coversed sine, haversed sine, hacoversed sine, exsecant, and excosecant.
Versed Sine
| ASP |
PHP |
function versin(x)
versin = 1 - cos(x)
end function
|
function versin($x)
{
return (1 - cos($x));
}
|
Coversed Sine
| ASP |
PHP |
function coversin(x)
coversin = 1 - sin(x)
end function
|
function coversin($x)
{
return (1 - sin($x));
}
|
Haversed Sine
| ASP |
PHP |
function haversin(x)
haversin = versin(x) / 2
end function
|
function haversin($x)
{
return (versin($x) / 2);
}
|
Hacoversed Sine
| ASP |
PHP |
function hacoversin(x)
hacoversin = coversin(x) / 2
end function
|
function hacoversin($x)
{
return (coversin($x) / 2);
}
|
Exsecant
| ASP |
PHP |
function exsec(x)
exsec = sec(x) - 1
end function
|
function exsec($x)
{
return (sec($x) - 1);
}
|
Excosecant
| ASP |
PHP |
function excsc(x)
excsc = csc(x) - 1
end function
|
function excsc($x)
{
return (csc($x) - 1);
}
|
Each of the six basic trigonometric functions has an inverse function. The inverse functions for sine, cosine, and tangent are already defined natively in PHP. The inverse function for tangent is defined in ASP, but we will create an alias for it to be consistent with the common abbreviation.
PHP defines several mathematical constants, one of which we'll be using here. M_PI_2 is equal to π divided by 2. If you're using ASP, you'll need to define this constant yourself.
Constants
| ASP |
Const M_PI = 3.14159265358979323846
Const M_PI_2 = M_PI / 2
|
Arcsine
| ASP |
function asin(x)
asin = atn(x / sqr(1 - x ^ 2))
end function
|
Arccosine
| ASP |
function acos(x)
acos = M_PI_2 - asin(x)
end function
|
Arctangent
| ASP |
function atan(x)
atan = atn(x)
end function
|
Arccosecant
| ASP |
function acsc(x)
acsc = asin(1 / x)
end function
|
| PHP |
function acsc($x)
{
return asin(1 / $x);
}
|
Arcsecant
| ASP |
function asec(x)
asec = M_PI_2 - acsc(x)
end function
|
| PHP |
function asec($x)
{
return (M_PI_2 - acsc($x));
}
|
Arccotangent
| ASP |
function acot(x)
acot = M_PI_2 - atn(x)
end function
|
| PHP |
function acot($x)
{
return (M_PI_2 - atan($x));
}
|
Hyperbolic Functions
The hyperbolic functions are like the circular trigonometric functions, but for hyperbola instead of circles. The hyperbolic functions for sine, cosine, and tangent are already defined natively in PHP.
Hyperbolic Sine
| ASP |
function sinh(x)
sinh = (exp(x) - exp(-x)) / 2
end function
|
Hyperbolic Cosine
| ASP |
function cosh(x)
cosh = (exp(x) + exp(-x)) / 2
end function
|
Hyperbolic Tangent
| ASP |
function tanh(x)
tanh = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
end function
|
Hyperbolic Cosecant
| ASP |
function csch(x)
csch = 2 / (exp(x) - exp(-x))
end function
|
| PHP |
function csch($x)
{
return (2 / (exp($x) - exp(-$x)));
}
|
Hyperbolic Secant
| ASP |
function sech(x)
sech = (2 / (exp(x) + exp(-x)))
end function
|
| PHP |
function sech($x)
{
return (2 / (exp($x) + exp(-$x)));
}
|
Hyperbolic Cotangent
| ASP |
function coth(x)
coth = (exp(x) + exp(-x)) / (exp(x) - exp(-x))
end function
|
| PHP |
function coth($x)
{
return (exp($x) + exp(-$x)) / (exp($x) - exp(-$x));
}
|
As with regular trigonometry, each hyperbolic function has an inverse. The inverse hyperbolic functions for sine, cosine, and tangent are already defined natively in PHP.
Inverse Hyperbolic Sine
| ASP |
function asinh(x)
asinh = log(x + sqr(x * x + 1))
end function
|
Inverse Hyperbolic Cosine
| ASP |
function acosh(x)
acosh = log(x + sqr(x * x - 1))
end function
|
Inverse Hyperbolic Tangent
| ASP |
function atanh(x)
atanh = log((1 + x) / (1 - x)) / 2
end function
|
Inverse Hyperbolic Cosecant
| ASP |
function acsch(x)
acsch = log((sin(x) * sqr(x * x + 1) + 1) / x)
end function
|
| PHP |
function acsch($x)
{
return (log((sin($x) * sqrt($x * $x + 1) + 1) / $x));
}
|
Inverse Hyperbolic Secant
| ASP |
function asech(x)
asech = log((sqr(-x * x + 1) + 1) / x)
end function
|
| PHP |
function asech($x)
{
return (log((sqrt(-$x * $x + 1) + 1) / $x));
}
|
Inverse Hyperbolic Cotangent
| ASP |
function acoth(x)
acoth = log((x + 1) / (x - 1)) / 2
end function
|
| PHP |
function acoth($x)
{
return (log(($x + 1) / ($x - 1)) / 2);
}
|
Gudermannian Functions
The Gudermannian function relates the circular and hyperbolic trigonometric functions without resorting to complex numbers. It also has an inverse.
Gudermannian Function
| ASP |
PHP |
function gd(x)
gd = 2 * atn(tanh(x / 2))
end function
|
function gd($x)
{
return (2 * atan(tanh($x / 2)));
}
|
Inverse Gudermannian Function
| ASP |
PHP |
function agd(x)
agd = atanh(sin(x))
end function
|
function agd($x)
{
return atanh(sin($x));
}
|