Trigonometric functions are the part of built-in mathematical functions. All these functions are vectorised. In this tutorial you will learn some built-in trigonometric functions in R and how to use these trigonometric functions in R.
Built-in Trigonometric functions
Commonly used trigonometric functions in R are listed below:
Function | Operation Performed |
---|---|
sin(x) |
sine value of x |
cos(x) |
cosine value of x |
tan(x) |
tangent value of x |
asin(x) |
arc-sine value of x |
acos(x) |
arc-cosine value of x |
atan(x) |
arc-tangent value of x |
sinh(x) |
hyperbolic sine of x |
cosh(x) |
hyperbolic cosine of x |
tanh(x) |
hyperbolic tangent of x |
asinh(x) |
hyperbolic arc-sine of x |
acosh(x) |
hyperbolic arc-cosine of x |
atanh(x) |
hyperbolic arc-tangent of x |
Examples of Trigonometric functions
R uses the argument to the trigonometric functions sin()
, cos()
and tan()
in radians.
sin()
function in R
To compute the $\sin(30^o)$ in R, we need to convert degree to radian as $30^o = \frac{30*\pi}{180}$ radian.
# compute sine of 30 degree angle
sin(30*pi/180)
[1] 0.5
Note that pi
is Special constant in R.
cos()
function in R
To compute the $\cos(45^o)$ in R, we need to convert degree to radian as $45^o = \frac{45*\pi}{180}$ radian.
# compute cos of 45 degree angle
cos(45*pi/180)
[1] 0.7071068
tan()
function in R
To compute the $\tan(60^o)$ in R, we need to convert degree to radian as $60^o = \frac{60*\pi}{180}$ radian.
# Compute tan of 60 degree angle
tan(60*pi/180)
[1] 1.732051
R always works with angles in radian and not degrees. So remember to convert the angle from degree to radian while calculating trigonometric functions.
Examples of Inverse Trigonometric functions
The inverse function returns the angle in radian. To convert it into degree, multiply the answer by $180/\pi$.
asin()
function in R
# Compute sin inverse of 0.5.
asin(0.5)*180/pi
[1] 30
acos()
function in R
# Compute cos inverse of 0.7071068.
acos(0.7071068)*180/pi
[1] 45
# Compute tan inverse of 60 degree
atan(1.732051)*180/pi
[1] 60
The result of the inverse trigonometric function is in radians. To get it the result in degrees multiply the result by $180/\pi$.
Examples of Hyperbolic Trigonometric functions
sinh()
function in R
The hyperbolic sine of $x$ is given by
$$ \sinh (x)=\frac{e^x- e^{-x}}{2} $$
sinh(30*pi/180)
[1] 0.5478535
cosh()
function in R
The hyperbolic cosine of $x$ is given by
$$ \cosh (x)=\frac{e^x+ e^{-x}}{2} $$
cosh(45*pi/180)
[1] 1.324609
tanh()
function in R
The hyperbolic tangent of $x$ is given by
$$ \tanh (x)=\frac{e^x- e^{-x}}{e^x+ e^{-x}} $$
tanh(60*pi/180)
[1] 0.7807144
Examples of Inverse Hyperbolic Trigonometric functions
asinh()
function in R
The inverse hyperbolic sine of $x$ is given by
$$ \text{asinh} (x) =\ln (x+\sqrt{x^2+1}) $$
To compute the inverse of sine hyperbolic of 0.5478535
, use the following function. Multiplying the result by $180/\pi$ gives you angle in degree.
asinh(0.5478535)*180/pi
[1] 30
acosh()
function in R
The inverse hyperbolic cosine of $x$ is given by
$$ \text{acosh} (x)=\ln (x+\sqrt{x^2-1}), x\geq 1 $$
To compute the inverse of cosine hyperbolic of 1.324609
, use the following function. Multiplying the result by $180/\pi$ gives you angle in degree.
acosh(1.324609)*180/pi
[1] 44.99999
atanh()
function in R
The inverse hyperbolic tangent of $x$ is given by
$$ \text{atanh} (x)=\frac{1}{2}\ln \bigg(\frac{1+x}{1-x}\bigg), |x| < 1 $$
To compute the inverse of cosine hyperbolic of 2.509178
, use the following function. Multiplying the result by $180/\pi$ gives you angle in degree.
atanh(0.7807144)*180/pi
[1] 59.99999
Endnote
In this tutorial you learned about trigonometric functions in R and how to use these functions in R.
To learn more about other built-in functions and user-defined functions in R, please refer to the following tutorials:
- Built-in Mathematical functions in R
- Built-in Special Mathematical functions in R
- Built-in Statistical functions in R
- Built-in Character functions in R
- User-defined functions in R Part I
- User-defined functions in R Part II
- Functions in R
Hopefully you enjoyed learning this tutorial on trigonometric functions in R. Hope the content is more than sufficient to understand trigonometric functions in R.