This action might not be possible to undo. Are you sure you want to continue?

David Eberly

Geometric Tools, LLC

http://www.geometrictools.com/

Copyright c 1998-2008. All Rights Reserved.

Created: March 2, 1999

Last Modiﬁed: March 2, 2008

Contents

1 Discussion 2

2 Gamma Function 2

2.1 Incomplete Gamma Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Error Function 3

4 Modiﬁed Bessel Function 4

1

1 Discussion

Although there are many special functions used in the mathematical world, the two I have used frequently

are the error function and the modiﬁed Bessel functions of orders 0 and 1. In addition I have a couple

other special functions, the logarithm of gamma and the incomplete gamma function, which are used for

computing the error function. The class declaration for special functions is

class mgcSpecialFunction

{

public:

mgcSpecialFunction () {;}

// gamma and related functions

float LogGamma (float x);

float Gamma (float x) { return exp(LogGamma(x)); }

float IncompleteGammaS (float a, float x); // series form

float IncompleteGammaCF (float a, float x); // continued fraction form

float IncompleteGamma (float a, float x);

// error functions

float Erf_NRC (float x); // Numerical Recipes in C, error function

float Erf (float x); // polynomial approximation to erf(x)

float Erfc (float x); // complementary error function, erfc(x) = 1-erf(x)

// modified Bessel functions of order 0 and 1

float ModBessel0 (float z);

float ModBessel1 (float z);

};

As new special functions are needed, they can be added to this class.

2 Gamma Function

The gamma function is deﬁned by

Γ(z) =

∞

0

t

z−1

e

−t

dt.

When z is an integer, then Γ(n+1) = n!, the factorial function. For large z this function can be quite large,

so it is common to work with its logarithm instead. We can use the formula

Γ(z + 1) =

√

2π(z + α + 1/2)

z+1/2

e

−(z+γ+1/2)

N

¸

k=0

c

k

z + k

+ ε

**for z > 0 and where α and N are user–selected. For α = 5 and N = 6, it can be shown that |ε| < 2 ×10
**

−7

.

The implementation of the logarithm of this function is float LogGamma (float x) and the gamma function

is obtained from it by float Gamma (float x).

2

2.1 Incomplete Gamma Function

An incomplete gamma function is deﬁned by

P(a, x) =

γ(a, x)

Γ(a)

=

1

Γ(a)

x

0

e

−t

t

a−1

dt

for a > 0. This equation also deﬁnes the function γ(a, x). A series representation for γ(a, x) is

γ(a, x) = e

−x

x

a

∞

¸

n=0

Γ(a)

Γ(a + 1 + n)

x

n

.

The series converges rapidly for x ≤ a + 1. Another incomplete gamma function is deﬁned by

Q(a, x) = 1 −P(a, x) =

Γ(a, x)

Γ(a)

for a > 0. This equation also deﬁnes the function Γ(a, x). A continued fraction representation for Γ(a, x) is

Γ(a, x) = e

−x

x

a

1

x+

1 −a

1+

1

x+

2 −a

1+

2

x+

· · ·

.

The continued fraction converges rapidly for x ≥ a + 1. An example of expanding a continued fraction is:

n

1

d

1

+

n

2

d

2

+

n

3

d

3

=

n

1

d

1

+

n2

d2+

n

3

d

3

.

The Numerical Recipes in C routines gammp (evaluates P(a, x)), gammq (evaluates Q(a, x)), gser (series

computation of γ(a, x)), and gcf (continued fraction computation of Γ(a, x)), are implemented (with diﬀerent

organization) as special functions IncompleteGammaS (series), IncompleteGammaCF (continued fractions),

and IncompleteGamma (P(a, x)).

3 Error Function

The error function is deﬁned by

erf(x) =

2

√

π

x

0

e

−t

2

dt.

The complementary error function is

erfc(x) = 1 −erf(x).

The code I use to calculate the complementary error function comes from Numerical Recipes in C. The

formula below comes from Chebyshev ﬁtting of the function.

t =

1

1+|x|/2

p(t) =

¸

9

k=0

a

k

t

k

(1 + ε)erfc(x) = t exp(−z

2

+ p(t))

3

where

a

0

= −1.26551223, a

1

= +1.00002368, a

2

= +0.37409196, a

3

= +0.09678418,

a

4

= −0.18628806, a

5

= +0.27886807, a

6

= −1.13520398, a

7

= +1.48851587.

a

8

= −0.82215223, a

9

= +0.17087277, |ε| < 1.2 ×10

−7

The implementation of this is Erf. The alternate routine Erf NRC uses the equivalence

erf(x) = P(0.5, x

2

), x ≥ 0,

where P is the incomplete gamma function.

An alternate way to compute the error function is through the use of incomplete gamma functions. In doing

so, some other special functions must be implemented.

4 Modiﬁed Bessel Function

The modiﬁed Bessel function of order zero is an even function given by

I

0

(z) =

1

π

π

0

exp(z cos θ) dθ =

∞

¸

m=0

(z

2

/4)

m

(m!)

2

.

This function is also a solution to the second–order linear diﬀerential equation: z

2

w

+zw

−z

2

w = 0. The

modiﬁed Bessel function of order one is an odd function given by

I

1

(z) = I

0

(z) =

1

π

π

0

cos θ exp(z cos θ) dθ

and it is a solution to the diﬀerential equation: z

2

w

+ zw

−(z

2

+ 1)w = 0. We can rewrite

F(R) = 2π exp

−

R

2

+ 1

2ρ

2

I

0

(R/ρ

2

) −RI

1

(R/ρ

2

)

.

Polynomial approximations to these functions are given below:

I

0

(z) =

6

¸

k=0

a

k

(z/3.75)

2k

+ ε, 0 ≤ z ≤ 3.75

where

a

0

= 1, a

1

= 3.5156229, a

2

= 3.0899424, a

3

= 1.2067492,

a

4

= 0.2659732, a

5

= 0.0360768, a

6

= 0.0045813, |ε| < 1.6 ×10

−7

and

z

1/2

e

−z

I

0

(z) =

8

¸

k=0

b

k

(z/3.75)

−k

+ ε, z ≥ 3.75

where

b

0

= +0.39894228, b

1

= +0.01328592, b

2

= +0.00225319, b

3

= −0.00157565,

b

4

= +0.00916281, b

5

= −0.02057706, b

6

= +0.02635537, b

7

= −0.01647633, b

8

= +0.00392377,

|ε| < 1.9 ×10

−7

4

and

z

−1

I

1

(z) =

6

¸

k=0

c

k

(z/3.75)

2k

+ ε, 0 ≤ z ≤ 3.75

where

c

0

= 0.5, c

1

= 0.87890549, c

2

= 0.51498869, c

3

= 0.15084934,

c

4

= 0.02658733, c

5

= 0.00301532, c

6

= 0.00032411, |ε| < 8 ×10

−9

and

z

1/2

e

−z

I

1

(z) =

8

¸

k=0

d

k

(z/3.75)

−k

+ ε, z ≥ 3.75

where

d

0

= +0.39894228, d

1

= −0.03988024, d

2

= −0.00362018, d

3

= +0.00163801,

d

4

= −0.01031555, d

5

= +0.02282967, d

6

= −0.02895312, d

7

= +0.01787654, d

8

= −0.00420059,

|ε| < 2.2 ×10

−7

The formulas can be found in Abramowitz and Stegun, Handbook of Mathematical Functions. No derivation

is given there. However, the idea is that for inputs close to zero, the function can be ﬁt to any desired

accuracy with a polynomial. For inputs far from zero, the function can be ﬁt to any desired accuracy with a

rational function. (Of course, the trick is choosing the forms of these functions and choosing parameters of

these functions to guarantee the accuracy. Probably a least squares approach can be used which minimizes

the maximum diﬀerence between function and approximation.)

5

// polynomial approximation to erf(x) float Erfc (float x). so it is common to work with its logarithm instead. the two I have used frequently are the error function and the modiﬁed Bessel functions of orders 0 and 1.1 Discussion Although there are many special functions used in the mathematical world. // series form float IncompleteGammaCF (float a. the factorial function. // error functions float Erf_NRC (float x). error function float Erf (float x). // complementary error function. When z is an integer. it can be shown that |ε| < 2 × 10−7 . The class declaration for special functions is class mgcSpecialFunction { public: mgcSpecialFunction () {. We can use the formula Γ(z + 1) = √ N 2π(z + α + 1/2)z+1/2 e−(z+γ+1/2) k=0 ck +ε z+k for z > 0 and where α and N are user–selected. } float IncompleteGammaS (float a. For α = 5 and N = 6. 2 Gamma Function ∞ The gamma function is deﬁned by Γ(z) = 0 tz−1 e−t dt. then Γ(n + 1) = n!. the logarithm of gamma and the incomplete gamma function. // Numerical Recipes in C. erfc(x) = 1-erf(x) // modified Bessel functions of order 0 and 1 float ModBessel0 (float z). float x). For large z this function can be quite large. float x). which are used for computing the error function. they can be added to this class. }. float ModBessel1 (float z). // continued fraction form float IncompleteGamma (float a. float x). In addition I have a couple other special functions. The implementation of the logarithm of this function is float LogGamma (float x) and the gamma function is obtained from it by float Gamma (float x). float Gamma (float x) { return exp(LogGamma(x)). 2 . As new special functions are needed.} // gamma and related functions float LogGamma (float x).

x)). x). Another incomplete gamma function is deﬁned by Q(a. x)). x). x) = γ(a. Γ(a + 1 + n) n=0 ∞ The series converges rapidly for x ≤ a + 1. x) = e−x xa Γ(a) xn . x) = e−x xa 1 1−a 1 2−a 2 ··· . d1 + d2 + d3 d1 + d n2n3 + 2 d3 The Numerical Recipes in C routines gammp (evaluates P (a. x) is γ(a. are implemented (with diﬀerent organization) as special functions IncompleteGammaS (series). x)).2. and IncompleteGamma (P (a. 2 The complementary error function is erfc(x) = 1 − erf(x). x) is Γ(a. x) = 1 − P (a. An example of expanding a continued fraction is: n1 n2 n3 n1 = . x+ 1+ x+ 1+ x+ The continued fraction converges rapidly for x ≥ a + 1. The code I use to calculate the complementary error function comes from Numerical Recipes in C. t p(t) (1 + ε)erfc(x) = = 1 1+|x|/2 9 k k=0 ak t = t exp(−z 2 + p(t)) 3 . x)). A series representation for γ(a.1 Incomplete Gamma Function An incomplete gamma function is deﬁned by P (a. A continued fraction representation for Γ(a. x)). gammq (evaluates Q(a. x) Γ(a) for a > 0. x) 1 = Γ(a) Γ(a) x e−t ta−1 dt 0 for a > 0. 3 Error Function 2 erf(x) = √ π x 0 The error function is deﬁned by e−t dt. and gcf (continued fraction computation of Γ(a. This equation also deﬁnes the function γ(a. This equation also deﬁnes the function Γ(a. IncompleteGammaCF (continued fractions). The formula below comes from Chebyshev ﬁtting of the function. gser (series computation of γ(a. x) = Γ(a.

z ≥ 3.0045813.39894228. |ε| < 1. a5 = +0.75)−k + ε.00002368. b1 = +0. a6 = −1.00157565.27886807.09678418. a2 = 3.00225319.00916281. b4 = +0.02635537.6 × 10−7 and z where b0 = +0. The modiﬁed Bessel function of order one is an odd function given by I1 (z) = I0 (z) = 1 π π cos θ exp(z cos θ) dθ 0 and it is a solution to the diﬀerential equation: z 2 w + zw − (z 2 + 1)w = 0. a3 = 1. a4 = 0.13520398.where a0 = −1.48851587.5. a4 = −0. a9 = +0. x2 ). a1 = +1. (m!)2 m=0 This function is also a solution to the second–order linear diﬀerential equation: z 2 w + zw − z 2 w = 0.5156229. Polynomial approximations to these functions are given below: 6 I0 (z) = k=0 ak (z/3.26551223. some other special functions must be implemented. where P is the incomplete gamma function. An alternate way to compute the error function is through the use of incomplete gamma functions.18628806.9 × 10−7 4 1/2 −z 8 e I0 (z) = k=0 bk (z/3. In doing so. We can rewrite F (R) = 2π exp − R2 + 1 2ρ2 I0 (R/ρ2 ) − RI1 (R/ρ2 ) .75)2k + ε. x ≥ 0.17087277.01647633. a2 = +0.2 × 10−7 The implementation of this is Erf. a7 = +1. b6 = +0.01328592. |ε| < 1. a5 = 0.00392377.02057706. b2 = +0.82215223.37409196. b5 = −0. a3 = +0.0360768. a8 = −0.2067492. 4 Modiﬁed Bessel Function ∞ The modiﬁed Bessel function of order zero is an even function given by I0 (z) = 1 π π exp(z cos θ) dθ = 0 (z 2 /4)m . b7 = −0. a6 = 0. |ε| < 1. b8 = +0.75 .75 where a0 = 1. The alternate routine Erf NRC uses the equivalence erf(x) = P (0. b3 = −0.0899424. a1 = 3.2659732. 0 ≤ z ≤ 3.

02282967.00032411. 0 ≤ z ≤ 3. (Of course.75)2k + ε. d5 = +0.02658733.39894228.75 where d0 = +0. Probably a least squares approach can be used which minimizes the maximum diﬀerence between function and approximation.01787654.15084934. d4 = −0. c6 = 0.75)−k + ε. d1 = −0. c5 = 0. z ≥ 3. c1 = 0.2 × 10−7 The formulas can be found in Abramowitz and Stegun.87890549. |ε| < 8 × 10−9 and z 1/2 e−z I1 (z) = k=0 8 dk (z/3.75 k=0 where c0 = 0. d8 = −0.00420059.01031555.00163801. No derivation is given there. |ε| < 2. d7 = +0. c4 = 0.51498869.and z −1 I1 (z) = 6 ck (z/3. d6 = −0.00362018. d3 = +0.5. the function can be ﬁt to any desired accuracy with a rational function.) 5 . the trick is choosing the forms of these functions and choosing parameters of these functions to guarantee the accuracy. c2 = 0. However. the function can be ﬁt to any desired accuracy with a polynomial. For inputs far from zero. d2 = −0. c3 = 0.00301532.02895312.03988024. Handbook of Mathematical Functions. the idea is that for inputs close to zero.

- Ενδοσχολική Βία, Project
- Μοσχάρι Με Noodles
- ορμη.pdf
- 2015 Aλυκ Xim(Full Permission)
- Σημειώσεις Word Ppt
- Οδηγίες Γ Λυκείου ΕΠΑΛ 2015-16
- Εγχειρίδιο Χρήσης MySchool_sxoleia
- EKO-LIST-251115
- Proficiency FINAL Student
- To Neyriko Systima
- sygkroysh ερμη γης
- ΑΚΤΙΝΕΣ Γ
- ΑΚΤΙΝΕΣ Γ
- ΕΞΙΣΩΣΕΙΣ Α ΒΑΘΜΟΥ
- ΤΕΣΤ ΣΤΑ ΣΥΝΟΛΑ
- Γεωργιαδης Γενικές Αρχές Αστικού Δικαίου
- αστικός κώδικας
- ΣΥΝΤΑΓΜΑΤΙΚΟ_ΣΠΥΡΟΠΟΥΛΟΣ
- αστικός κώδικας
- Εισαγωγή-στη-Γ.Θ.Σ.-και-τη-Κοσμολογία
- 0310808v2 orizontes lineweaver
- Supersymmetric Unification
- Differential Geometry and Lie Groups for Physicists
- sosΦSX
- a gym

- Pre-Algebra Segment 1
- 2.4 Continuity
- C_2-4_LP-1
- Functions and Mappings
- AdMaths1-15.pdf
- separation variable
- Joel
- PC FUNCTIONS Basic Function Problems
- Problem Set 9.pdf
- Spring 2010 MidTerm OPKST MTH101 - Calculus I My Own Sol
- Calc Notes 010 r
- Foundations of Mathematics - (Malestrom)
- About inverse derivatives and convergence of perturbative series
- PartI
- Pre Calculus Finals ( July 2012 )
- An Overview of Analytic Geometry
- IVT
- Slightly ?? ∗ -continuous functions and totally ?? ∗ -continuous functions in Topological spaces
- Types of Functions
- AITS2012-01-PT1P2-CMP-161011
- Characterising Functions
- 312 Lecture Notes F12 Part2
- PS-1-2007
- Lecture 12
- fyc17
- Linear Systems
- huxley.txt
- c3 1 Functions
- Elementary Algebra p
- Elementary Functions
- Special Functions

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd