Top Banner
Computing special functions with the trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain January 15, 2010 J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 1 / 25
44

Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Sep 05, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Computing special functions with thetrapezoidal rule

Javier Segura

Departamento de Matemáticas, Estadística y ComputaciónUniversidad de Cantabria, Spain

January 15, 2010

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 1 / 25

Page 2: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Contents:

1 What is a Special Function? Why compute them?What is it?Why compute them?

2 A case study: Airy functionsConvergent and divergent seriesMethods for intermediate regions. Numerical quadrature

3 Why the trapezoidal rule?Trapezoidal rule: simple and sometimes optimalSteepest descent and the trapezoidal ruleAdditional examples where saddle point analysis is fruitfulTrapezoidal rules with changes of variable

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 2 / 25

Page 3: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Contents:

1 What is a Special Function? Why compute them?What is it?Why compute them?

2 A case study: Airy functionsConvergent and divergent seriesMethods for intermediate regions. Numerical quadrature

3 Why the trapezoidal rule?Trapezoidal rule: simple and sometimes optimalSteepest descent and the trapezoidal ruleAdditional examples where saddle point analysis is fruitfulTrapezoidal rules with changes of variable

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 2 / 25

Page 4: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Contents:

1 What is a Special Function? Why compute them?What is it?Why compute them?

2 A case study: Airy functionsConvergent and divergent seriesMethods for intermediate regions. Numerical quadrature

3 Why the trapezoidal rule?Trapezoidal rule: simple and sometimes optimalSteepest descent and the trapezoidal ruleAdditional examples where saddle point analysis is fruitfulTrapezoidal rules with changes of variable

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 2 / 25

Page 5: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?

What is an elementary function? Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 6: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?What is an elementary function?

Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 7: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?What is an elementary function? Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 8: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?What is an elementary function? Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?

Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 9: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?What is an elementary function? Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category

⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 10: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

What is a Special Function?What is an elementary function? Everybody knowsElementary functions and operations:

1 +,-,*,/2 Polynomials3 Trigonometric4 Exponential and logarithm

Elementary functions (trigonometric functions, exponential, log):algorithms based on polynomial approximation and/or table lookup;Shift-and-Add algorithms.

Enough?Of course, not.There is "a bunch" of useful functions which do not fall inside thisnarrow category⇒ SPECIAL FUNCTIONS

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 3 / 25

Page 11: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

1 The error function: erf(x) = 2√π

∫ x

0e−t2

dt

2 The gamma function: Γ(α) =

∫ +∞

0xαe−xdx

3 The Airy functions: solutions of y ′′(z)− zy(z) = 04 And many more, some of them depending on several parameters

(hypergeometric functions among them)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 4 / 25

Page 12: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

1 The error function: erf(x) = 2√π

∫ x

0e−t2

dt

2 The gamma function: Γ(α) =

∫ +∞

0xαe−xdx

3 The Airy functions: solutions of y ′′(z)− zy(z) = 04 And many more, some of them depending on several parameters

(hypergeometric functions among them)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 4 / 25

Page 13: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

1 The error function: erf(x) = 2√π

∫ x

0e−t2

dt

2 The gamma function: Γ(α) =

∫ +∞

0xαe−xdx

3 The Airy functions: solutions of y ′′(z)− zy(z) = 0

4 And many more, some of them depending on several parameters(hypergeometric functions among them)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 4 / 25

Page 14: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? What is it?

1 The error function: erf(x) = 2√π

∫ x

0e−t2

dt

2 The gamma function: Γ(α) =

∫ +∞

0xαe−xdx

3 The Airy functions: solutions of y ′′(z)− zy(z) = 04 And many more, some of them depending on several parameters

(hypergeometric functions among them)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 4 / 25

Page 15: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? Why compute them?

Why compute special functions?

Some reasons:1 For the same reason we compute elementary functions, because

they are needed.

2 When additional functions can be computed, the toolbox ofavailable functions becomes richer and more powerful

3 In particular, some of these non-elementary functions can be usedas approximation tools.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 5 / 25

Page 16: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? Why compute them?

Why compute special functions?

Some reasons:1 For the same reason we compute elementary functions, because

they are needed.2 When additional functions can be computed, the toolbox of

available functions becomes richer and more powerful

3 In particular, some of these non-elementary functions can be usedas approximation tools.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 5 / 25

Page 17: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

What is a Special Function? Why compute them? Why compute them?

Why compute special functions?

Some reasons:1 For the same reason we compute elementary functions, because

they are needed.2 When additional functions can be computed, the toolbox of

available functions becomes richer and more powerful3 In particular, some of these non-elementary functions can be used

as approximation tools.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 5 / 25

Page 18: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions

Airy functions are the solution of the ODE:

The Airy equation

y ′′(z)− zy(z) = 0

Ai(z) is the recessive solution as |z| → ∞, arg(z) < π/3.

Recent methods for computing this function in the complex plane are:1 Fabijonas, Lozier, Olver (ACM TOMS 2004)2 Gil, Segura, Temme (ACM TOMS 2002)

The Airy equation can be seen as the most elementary departure from

y ′′ + Ay = 0, A constant

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 6 / 25

Page 19: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions

Airy functions are the solution of the ODE:

The Airy equation

y ′′(z)− zy(z) = 0

Ai(z) is the recessive solution as |z| → ∞, arg(z) < π/3.Recent methods for computing this function in the complex plane are:

1 Fabijonas, Lozier, Olver (ACM TOMS 2004)2 Gil, Segura, Temme (ACM TOMS 2002)

The Airy equation can be seen as the most elementary departure from

y ′′ + Ay = 0, A constant

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 6 / 25

Page 20: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions

Airy functions as approximation tools

Airy equation y ′′ − zy = 0. Solutions for real z:

Many uniform asymptotic expansions for solutions of equations withturning points involve Airy functions.For instance (just to mention two examples appearing later):

1 y ′′ + (a− x2/4)y = 0 (parabolic cylinder functions) around theparabola a = x2/4.

2 x2y ′′ + xy ′ + (a2 − x2)y = 0 (modified Bessel functions ofimaginary order) around |x | = |a|.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 7 / 25

Page 21: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions

Airy functions as approximation tools

Airy equation y ′′ − zy = 0. Solutions for real z:

Many uniform asymptotic expansions for solutions of equations withturning points involve Airy functions.

For instance (just to mention two examples appearing later):1 y ′′ + (a− x2/4)y = 0 (parabolic cylinder functions) around the

parabola a = x2/4.2 x2y ′′ + xy ′ + (a2 − x2)y = 0 (modified Bessel functions of

imaginary order) around |x | = |a|.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 7 / 25

Page 22: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions

Airy functions as approximation tools

Airy equation y ′′ − zy = 0. Solutions for real z:

Many uniform asymptotic expansions for solutions of equations withturning points involve Airy functions.For instance (just to mention two examples appearing later):

1 y ′′ + (a− x2/4)y = 0 (parabolic cylinder functions) around theparabola a = x2/4.

2 x2y ′′ + xy ′ + (a2 − x2)y = 0 (modified Bessel functions ofimaginary order) around |x | = |a|.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 7 / 25

Page 23: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions Convergent and divergent series

The goal: computing a numerically satisfactory pair of solutions of theAiry equation for real z > 0. A numerically satisfactory pair shouldcomprise the recessive solution.

1 We try Maclaurin series and get two independent solutions:

y1(z) =∞∑

k=0

3k(

13

)k

z3k

(3k)!, y2(z) =

∞∑k=0

3k(

23

)k

z3k+1

(3k + 1)!(1)

They converge in C, but limz→+∞ y1,2(z) = +∞.2 The functions Y (z) = z1/4y(z) are solutions of

Y (ζ) + A(ζ)Y (ζ) = 0, with A(ζ) = −1 + 5/(36ζ2), ζ = 2/3z3/2

From this, we can obtain the well-known asymptotics for large z:

Ai(z) ∼ z−1/4e−ζ∑∞

m=0 amζ−m,

Bi(z) ∼ 2z−1/4eζ∑∞

m=0(−1)mamζ−m

ζ = 23z3/2 ,a0 = (2

√π)−1

am+1 = −λ+ m(m + 1)2(m + 1)

am, m = 0,1,2, . . . .

(2)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 8 / 25

Page 24: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

A case study: Airy functions Methods for intermediate regions. Numerical quadrature

For improving the computation of Airy functions, additionalapproximations shoud be considered for intermediate z. Somepossibilities:

1 Chebyshev expansions (for real z only)2 Numerical quadrature (for z ∈ C) [Gil, Segura, Temme 2002]3 Numerical integration of the ODE (for z ∈ C) [Fabijonas, Olver,

Lozier 2004]

We concentrate on quadrature methods, with special emphasis in thetrapezoidal rule. Let’s see why.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 9 / 25

Page 25: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule?

The trapezoidal rule

I(f ) =

∫ b

af (x)dx ≈ T (f ,h) =

h2

(f0 + fn) + hn−1∑i=1

fi , h =b − a

nf

f(x)

f

x

0

n

a=x0 x1b=x n

Features:Recursivity: T (f ,h/2) = T (f ,h) + h

2∑

i∈{new}fi

Error: I(f )− T (f ,h) = O(h2), but...J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 10 / 25

Page 26: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rule: simple and sometimes optimal

Theorem (Euler–Maclaurin)Let f (x) be a function with 2m + 2 continuous derivatives in [x0, xn],then R(f ,h) = I(f )− T (f ,h) admits the expansion

R(f ,h) =m∑

l=1

B2l

(2l)!h2l(

f (2l−1)(x0)− f (2l−1)(xn))

− B2m+2

(2m + 2)!(xn − x0)h2m+2f (2m+2)(ζ)

(3)

for some ζ in [x0, xn]. Bk are the Bernoulli numbers.

CorollaryIf f is periodic and has a continuous kth derivative, and if the integral istaken over a full period, then

R(f ,h) = O(hk ), h→∞

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 11 / 25

Page 27: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rule: simple and sometimes optimal

Example:

πJ0(x) =

∫ π

0cos(x sin t) dt = h+h

n−1∑j=1

cos [x sin(hj)]+R(f ,h), h = π/n

n R(f ,h)

4 −.12 10−000

8 −.48 10−006

16 −.11 10−021

32 −.13 10−062

64 −.13 10−163

128 −.53 10−404

It can be proved that |R(f ,h)| ≤ 2ex/2 (x/2)n

(2n)!, h = π/n

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 12 / 25

Page 28: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rule: simple and sometimes optimal

The trapezoidal rule is also an interesting quadrature method forintegrals in R for similar reasons.

TheoremLet ∫ +∞

−∞f (x)dx = h

∞∑i=−∞

fi + E(f ,h), fi = f (ih)

If f (x) is real for real x and f (z) is analytic in an open set containingthe strip

{z = x + iy |x ∈ R,−a ≤ y ≤ a}

then

|E(f ,h)| ≤ e−πa/h

2 sinh(πa/h)

∫ +∞

−∞|f (x + ia)|dx

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 13 / 25

Page 29: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rule: simple and sometimes optimal

Example:

exK0(x) =12

∫ +∞

−∞e−x(cosh(t)−1)dt = 1

2 h + h∞∑j=1

e−x(cosh(hj)−1) + R(f ,h). (4)

For x = 5 and several values of h we obtain the values of Table 1 (j0 denotesthe number of terms used in the series in (4)). We see that already for h = 1

4and 12 function evaluations, IEEE double precision can be obtained. �

Table: Values of R(f ,h) in (4) for x = 5.

h j0 R0(h)

1 2 −0.18 10−001

1/2 5 −0.24 10−006

1/4 12 −0.65 10−015

1/8 29 −0.44 10−032

1/16 67 −0.19 10−066

1/32 156 −0.55 10−136

1/64 355 −0.17 10−272

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 14 / 25

Page 30: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rule: simple and sometimes optimal

CorollaryThe error of the trapezoidal rule for computing∫ +∞

−∞e−wx2

f (x)dx , w > 0

isE(f ,h) = O(e−π

2/wh2), h→ 0

if f (z) is analytic on a strip

{z = x + iy |x ∈ R,−a ≤ y ≤ a}

with a ≥ πwh

Of course, if f (x) is even, the same can be said for∫ +∞

0 e−wx2f (x)dx .

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 15 / 25

Page 31: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Many special functions can be written as integral representations.For instance, for real x :

Ai(x) = 1π∫ +∞

0 cos(w3

3 + xw)dw = 1π∫ +∞−∞ eφ(w)dw

φ(w) = i(w3

3 + xw)(5)

Application of the trapezoidal rule (or the like) on the Airy integralrepresentation is very unstable because of its oscillatory nature.The steepest descent method can be used to find alternative integralrepresentations.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 16 / 25

Page 32: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

More generally SFs have representations

I =

∫C

eφ(w)dw (6)

where C is some contour in the complex plane going to infinity at bothends.Stable representations: deform the contour of integration in thecomplex plane and integrate over a curve where =(φ) = constant (nooscillations). The curve must pass through one of the saddles of φ(w),w0 (φ′(w0) = 0) and descend through the valleys of |φ(w)|.

I = eφ(w0)

∫C′

eψ(w)dw , ψ(w) = φ(w)− φ(w0) (7)

The new integrand is 1 at the saddle and will usually decay very fast as|w − w0| → +∞.Good for the trapezoidal rule!

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 17 / 25

Page 33: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

A trivial example

I =∫ +∞−∞ cos(w2/2 + xw)dw = <(F ),

F =∫ +∞−∞ eφ(w)dw , φ(t) = i(w2/2 + xw)

φ′(w0) = 0→ w0 = −x

The path w = v − x + iv , v ∈ (−∞,+∞) is of steepest descent (SD)and one can deform the original path to the SD path, wheredw = (1 + i)dv , <(φ(w)) = −v2 and:

F =

∫ +∞

−∞eφ(w)dw = eφ(w0)(1 + i)

∫ +∞

−∞e−v2

dv

The remaining integral is suited for the trapezoidal rule (not needed).With this F = e−ix2/2(1 + i)

√π and I =

√2π cos(x2/2− π/4).

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 18 / 25

Page 34: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

A not so simple example: Airy functions

Let us consider x > 0. We start from

Ai(x) =1π

∫ +∞

0cos

(t3

3+ xt

)dt =

∫ +∞

−∞ei(t3/3+xt)dt

φ′(t0) = 0⇒ t0 = ±i√

x

Take t0 = i√

x , then =(φ(t)) = =(φ(t0)) over the t = u + iv curve

C = {t = u + iv : v =√

u2/3 + x ,u ∈ (−∞,∞)}

Ai(x) =1π

eφ(t0)

∫ +∞

−∞eφ(t)−φ(t0)(1 + i

13

u/√

u2/3 + x)du

and φ(t)− φ(t0) ∼ − 83√

3|u|3 as u → ±∞

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 19 / 25

Page 35: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Airy functions for complex argumentsA better idea for complex variables is to consider

Ai(z) =1

2πi

ZC

e13 w3−zw dw, ph z ∈ [0,

2

3π] (8)

C: contour starting at∞e−iπ/3 and terminating at∞e+iπ/3 (in the valleys of the integrand).Let

φ(w) = 13 w3 − zw. (9)

The saddle points are w0 =√

z and−w0 and follow from solving φ′(w) = w2 − z = 0.The saddle point contour (the path of steepest descent) that runs through the saddle point w0 is defined by

=[φ(w)] = =[φ(w0)]. (10)

We writez = x + iy = reiθ

, w = u + iv, w0 = u0 + iv0. (11)

Thenu0 =

√r cos 1

2 θ, v0 =√

r sin 12 θ, x = u2

0 − v20 , y = 2u0v0. (12)

The path of steepest descent through w0 is given by the equation

u = u0 +(v − v0)(v + 2v0)

u0 +q

13 (v2 + 2v0v + 3u2

0 )

– , −∞ < v <∞. (13)

Again, the resulting integral is suited for the trapezoidal rule.J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 20 / 25

Page 36: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Numerical quadrature: Airy functionsExamples for r = 5 and a few θ−values (θ = 0, π/3,2π/3, π) are shown in thefigure. The saddle points are located on the circle with radius

√r and are

indicated by small dots.

u

v5.0

5.0

−5.0

−5.0

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 21 / 25

Page 37: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Numerical quadrature: Airy functionsExamples for r = 5 and a few θ−values (θ = 0, π/3,2π/3, π) are shown in thefigure. The saddle points are located on the circle with radius

√r and are

indicated by small dots.

u

v5.0

5.0

−5.0

−5.0

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 21 / 25

Page 38: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Strong points of the method:1 The main contribution is factored out2 The resulting representations are non-oscillatory3 The integral usually becomes appropriate for direct application of

the trapezoidal rule (at least when both end points are at∞).4 Quadrature with authomatic control of stepsize is possible.

Some difficulties1 Non smoothness: the steepest descent curves may become

non-smooth, particularly close to the boundaries of application.

[Cure: consider approximations of the steepest decent paths]2 Not all resulting integrals are always fine for the quadrature rule,

let’s admit. [Cure: consider transforming the variable so thatbecomes fine, or...]

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 22 / 25

Page 39: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Strong points of the method:1 The main contribution is factored out2 The resulting representations are non-oscillatory3 The integral usually becomes appropriate for direct application of

the trapezoidal rule (at least when both end points are at∞).4 Quadrature with authomatic control of stepsize is possible.

Some difficulties1 Non smoothness: the steepest descent curves may become

non-smooth, particularly close to the boundaries of application.[Cure: consider approximations of the steepest decent paths]

2 Not all resulting integrals are always fine for the quadrature rule,let’s admit.

[Cure: consider transforming the variable so thatbecomes fine, or...]

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 22 / 25

Page 40: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Strong points of the method:1 The main contribution is factored out2 The resulting representations are non-oscillatory3 The integral usually becomes appropriate for direct application of

the trapezoidal rule (at least when both end points are at∞).4 Quadrature with authomatic control of stepsize is possible.

Some difficulties1 Non smoothness: the steepest descent curves may become

non-smooth, particularly close to the boundaries of application.[Cure: consider approximations of the steepest decent paths]

2 Not all resulting integrals are always fine for the quadrature rule,let’s admit. [Cure: consider transforming the variable so thatbecomes fine, or...]

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 22 / 25

Page 41: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Steepest descent and the trapezoidal rule

Alternatives are available in some cases:

Ai(x) = 1√π(48)1/6Γ(5/6)

e−ζζ−1/6 ∫ +∞0

(2 + t

ζ

)−1/6t−1/6e−tdt ,

ζ = 23x3/2

Good for Gauss-Legendre quadrature (α = −1/6).Good but not as flexible as the trapezoidal rule.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 23 / 25

Page 42: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Additional examples where saddle point analysis is fruitful

Saddle point analysis + trapezoidal rule are also used for:

1 Scorer function, solution of y′′ − zy = 1π

Hi (z) = 1πR +∞

0 ezt−1/3t3 dt, z ∈ C, phz ∈ [2π/3, π][′02]

2 Modified Bessel functions of imaginary order, solution of x2y′′ + xy′ + (a2 − x2)y = 0

Kia(x) = 12R +∞−∞ e−x cosh(t) cos(at)dt, x ∈ R [′04]

3 Parabolic cylinder functions, solution of y′′ + (a− x2/4)y = 0

U(a, x) = ex2/4

i√

RC e−xs+ 1

2 s2s−a−1/2ds, x ∈ R [′06]

C = {s ∈ C : s = x + iy, x > 0, y ∈ (−∞,+∞)}

4 Conical function

P−µ−1/2+iτ (x) =Γ(

1

2+ µ)(1− x2)µ/2

Γ(µ− ν)Γ(1 + µ + ν)√

R +∞−∞(x + cosh t)−µ−1/2 cos(τ t)dt [′09]

A chain of approximations Ai(z)⇒ Kia(x)⇒ P−µ−1/2+iτ (x)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 24 / 25

Page 43: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Additional examples where saddle point analysis is fruitful

Saddle point analysis + trapezoidal rule are also used for:

1 Scorer function, solution of y′′ − zy = 1π

Hi (z) = 1πR +∞

0 ezt−1/3t3 dt, z ∈ C, phz ∈ [2π/3, π][′02]

2 Modified Bessel functions of imaginary order, solution of x2y′′ + xy′ + (a2 − x2)y = 0

Kia(x) = 12R +∞−∞ e−x cosh(t) cos(at)dt, x ∈ R [′04]

3 Parabolic cylinder functions, solution of y′′ + (a− x2/4)y = 0

U(a, x) = ex2/4

i√

RC e−xs+ 1

2 s2s−a−1/2ds, x ∈ R [′06]

C = {s ∈ C : s = x + iy, x > 0, y ∈ (−∞,+∞)}

4 Conical function

P−µ−1/2+iτ (x) =Γ(

1

2+ µ)(1− x2)µ/2

Γ(µ− ν)Γ(1 + µ + ν)√

R +∞−∞(x + cosh t)−µ−1/2 cos(τ t)dt [′09]

A chain of approximations Ai(z)⇒ Kia(x)⇒ P−µ−1/2+iτ (x)

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 24 / 25

Page 44: Computing special functions with the trapezoidal rule · trapezoidal rule Javier Segura Departamento de Matemáticas, Estadística y Computación Universidad de Cantabria, Spain ...

Why the trapezoidal rule? Trapezoidal rules with changes of variable

Most of the resulting integrals are suitable for the trapezoidal rule, while other can betransformed to make them suitable for the TR.For instance, consider the function

erf (t) =2√π

Z t

0e−y2

dy (14)

Using the change of variables x = erf (t) we have:Z +1

−1f (x)dx =

2√π

Z +∞

−∞f (erf (t))e−t2

dt

Very efficient when f is an entire function.Other changes of variable are available for semi-infinite intervals. and integrands withend-point singularitiesFor more details see, for instance:

1 C. Schwartz, “Numerical integration of analytic functions" , J. Comp. Phys. 4(1969), 19-29.

2 H. Takahasi and M. Mori, “Quadrature formulas obtained by variabletransformation", Numer. Math. 12 (1973), 206-219.

3 H. Takahasi and M. Mori, “Double exponential formulas for numericalintegration", Publications RIMS, Kyoto U. 9 (1974), 721-741.

4 A. Gil, J. Segura, N.M. Temme, “Numerical Methods for Special Functions",SIAM (2007), Chap. 5.

J. Segura (Universidad de Cantabria) The trapezoidal rule and SF January 15, 2010 25 / 25