Description Usage Arguments Value Author(s) References Examples
A collection and description of special mathematical
functions. The functions include the error function,
the Psi function, the incomplete Gamma function, the
Gamma function for complex argument, and the
Pochhammer symbol. The Gamma function the logarithm
of the Gamma function, their first four derivatives,
and the Beta function and the logarithm of the Beta
function are part of R's base package. For example,
these functions are required to valuate Asian Options
based on the theory of exponential Brownian motion.
The functions are:
erf | the Error function, |
gamma* | the Gamma function, |
lgamma* | the logarithm of the Gamma function, |
digamma* | the first derivative of the Log Gamma function, |
trigamma* | the second derivative of the Log Gamma function, |
tetragamma* | the third derivative of the Log Gamma function, |
pentagamma* | the fourth derivative of the Log Gammafunction, |
beta* | the Beta function, |
lbeta* | the logarithm of the Beta function, |
Psi | Psi(x) the Psi or Digamma function, |
igamma | P(a,x) the incomplete Gamma function, |
cgamma | Gamma function for complex argument, |
Pochhammer | the Pochhammer symbol. |
The functions marked by an asterisk are part of R's base package.
1 2 3 4 5 |
x |
[erf] - |
a |
a complex numeric value or vector. |
n |
an integer value |
log |
a logical, if |
The functions return the values of the selected special mathematical function.
Diethelm Wuertz for the Rmetrics R-port.
Abramowitz M., Stegun I.A. (1972); Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, 9th printing, New York, Dover Publishing.
Artin, E. (1964); The Gamma Function, New York, Holt, Rinehart, and Winston Publishing.
Weisstein E.W. (2004); MathWorld–A Wolfram Web Resource, http://mathworld.wolfram.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | ## Calculate Error, Gamma and Related Functions
## gamma -
# Abramowitz-Stegun: Figure 6.1
x = seq(-4.01, 4.01, by = 0.011)
plot(x, gamma(x), ylim = c(-5,5), type = "l", main = "Gamma Function")
lines(x = c(-4, 4), y = c(0, 0))
## Psi -
# Abramowitz-Stegun: Figure 6.1
x = seq(-4.01, 4.01, by = 0.011)
plot(x, Psi(x), ylim = c(-5, 5), type = "l", main = "Psi Function")
lines(x = c(-4, 4), y = c(0, 0))
# Note: Is digamma defined for positive values only ?
## igamma -
# Abramowitz-Stegun: Figure 6.3.
gammaStar = function(x, a) { igamma(x,a)/x^a }
# ... create Figure as an exercise.
## igamma -
# Abramowitz-Stegun: Formula 6.5.12
# Relation to Confluent Hypergeometric Functions
a = sqrt(2)
x = pi
Re ( (x^a/a) * kummerM(-x, a, 1+a) )
Re ( (x^a*exp(-x)/a) * kummerM(x, 1, 1+a) )
pgamma(x,a) * gamma(a)
igamma(x, a)
## cgamma -
# Abramowitz-Stegun: Tables 6.7
x = 1
y = seq(0, 5, by = 0.1); x = rep(x, length = length(y))
z = complex(real = x, imag = y)
c = cgamma(z, log = TRUE)
cbind(y, Re(c), Im(c))
## cgamma -
# Abramowitz-Stegun: Examples 4-8:
options(digits = 10)
gamma(6.38); lgamma(56.38) # 1/2
Psi(6.38); Psi(56.38) # 3/4
cgamma(complex(real = 1, imag = -1), log = TRUE ) # 5
cgamma(complex(real = 1/2, imag = 1/2), log = TRUE ) # 6
cgamma(complex(real = 3, imag = 7), log = TRUE ) # 7/8
|
Loading required package: timeDate
Loading required package: timeSeries
Loading required package: fBasics
Loading required package: fOptions
[1] 0.8091978
[1] 0.8091978
[1] 0.8091978
[1] 0.9127168
y
[1,] 0.0 -8.881784e-16 0.000000000
[2,] 0.1 -8.197781e-03 -0.057322940
[3,] 0.2 -3.247629e-02 -0.112302223
[4,] 0.3 -7.194625e-02 -0.162820672
[5,] 0.4 -1.252894e-01 -0.207155826
[6,] 0.5 -1.909455e-01 -0.244058299
[7,] 0.6 -2.672901e-01 -0.272743810
[8,] 0.7 -3.527687e-01 -0.292826351
[9,] 0.8 -4.459788e-01 -0.304225603
[10,] 0.9 -5.457051e-01 -0.307074376
[11,] 1.0 -6.509232e-01 -0.301640320
[12,] 1.1 -7.607840e-01 -0.288266614
[13,] 1.2 -8.745905e-01 -0.267330581
[14,] 1.3 -9.917728e-01 -0.239216784
[15,] 1.4 -1.111865e+00 -0.204300724
[16,] 1.5 -1.234483e+00 -0.162939769
[17,] 1.6 -1.359312e+00 -0.115468794
[18,] 1.7 -1.486090e+00 -0.062198698
[19,] 1.8 -1.614595e+00 -0.003416631
[20,] 1.9 -1.744644e+00 0.060612874
[21,] 2.0 -1.876079e+00 0.129646316
[22,] 2.1 -2.008764e+00 0.203459474
[23,] 2.2 -2.142584e+00 0.281845658
[24,] 2.3 -2.277438e+00 0.364614049
[25,] 2.4 -2.413238e+00 0.451588152
[26,] 2.5 -2.549907e+00 0.542604406
[27,] 2.6 -2.687376e+00 0.637510919
[28,] 2.7 -2.825586e+00 0.736166352
[29,] 2.8 -2.964481e+00 0.838438913
[30,] 2.9 -3.104015e+00 0.944205473
[31,] 3.0 -3.244144e+00 1.053350771
[32,] 3.1 -3.384829e+00 1.165766713
[33,] 3.2 -3.526034e+00 1.281351746
[34,] 3.3 -3.667728e+00 1.400010297
[35,] 3.4 -3.809881e+00 1.521652275
[36,] 3.5 -3.952467e+00 1.646192624
[37,] 3.6 -4.095461e+00 1.773550923
[38,] 3.7 -4.238841e+00 1.903651019
[39,] 3.8 -4.382587e+00 2.036420710
[40,] 3.9 -4.526679e+00 2.171791444
[41,] 4.0 -4.671100e+00 2.309698057
[42,] 4.1 -4.815833e+00 2.450078530
[43,] 4.2 -4.960864e+00 2.592873771
[44,] 4.3 -5.106178e+00 2.738027415
[45,] 4.4 -5.251763e+00 2.885485639
[46,] 4.5 -5.397606e+00 3.035197000
[47,] 4.6 -5.543696e+00 3.187112279
[48,] 4.7 -5.690023e+00 3.341184344
[49,] 4.8 -5.836576e+00 3.497368019
[50,] 4.9 -5.983346e+00 3.655619965
[51,] 5.0 -6.130324e+00 3.815898575
[1] 232.4367103
[1] 169.854974
[1] 1.772755883
[1] 4.023219877
[1] -0.6509231993+0.3016403205i
[1] 0.1123872428-0.7507292021i
[1] -5.16252322+10.11625224i
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.