In R language we can also use arithmetic functions to solve complex calculations in mathematic.
There are many kinds of arithmetic functions that we can used in R language, including:
Logarithm is the inverse function to exponentiation. Formula: \(logb = (b^{x}\)) = x
Examples:
log2(16) # Logarithm base 2 for 16 (2^4)
## [1] 4
log2(1024) # Logarithm base 2 for 16 (2^10)
## [1] 10
Example:
exp(10) # Exponential for 10
## [1] 22026.47
Trigonometry studies relationships between side lengths and angles of triangles. Like sin, cos, tan, etc.
Example:
x = 1
sin(x) # sin 1
## [1] 0.841471
cos(x) # cos 1
## [1] 0.5403023
tan(x) # tan 1
## [1] 1.557408
asin(x) # arc-sin 1
## [1] 1.570796
acos(x) # arc-cos 1
## [1] 0
atan(x) #arc-tan 1
## [1] 0.7853982
In pracma package, trigonometry functions can be extended. The functions including:
library(pracma)
## Warning: package 'pracma' was built under R version 4.2.2
a = 1
cot(a) # cotan 1
## [1] 0.6420926
csc(a) # cosecan 1
## [1] 1.188395
sec(a) # secan 1
## [1] 1.850816
acot(a) # arc-cotan 1
## [1] 0.7853982
acsc(a) # arc-cosecan 1
## [1] 1.570796
asec(a) # arc-secan 1
## [1] 0
In mathematics, hyperbolic functions are analogues of the ordinary trigonometric functions, but defined using the hyperbola rather than the circle.
Example:
cosh(x)
## [1] 1.543081
sinh(x)
## [1] 1.175201
tanh(x)
## [1] 0.7615942
acosh(x)
## [1] 0
asinh(x)
## [1] 0.8813736
atanh(x)
## [1] Inf
In pracma package, hyperbolic functions can be extended. The functions including:
library(pracma)
coth(x)
## [1] 1.313035
csch(x)
## [1] 0.8509181
sec
## function (z)
## {
## stopifnot(is.numeric(z) || is.complex(z))
## 1/cos(z)
## }
## <bytecode: 0x000001d568155dd0>
## <environment: namespace:pracma>
acoth(x)
## [1] Inf
acsch(x)
## [1] 0.8813736
asech(x)
## [1] 0
Example:
abs(-100)
## [1] 100
Example:
sqrt(9)
## [1] 3