You are on page 1of 7

Multiple Integrals

Improper Integrals

Multiple Integrals
Improper Integrals

Outline

Numerical Analysis and Computing


Lecture Notes #09
Numerical Integration and Differentiation
Multiple Integrals; Improper Integrals

Multiple Integrals
CSR in n-D
Non-Rectangular Domains

Improper Integrals
Calculus Treasures
Taylor Expansions... Surprise!

Joe Mahaffy,
hmahaffy@math.sdsu.edui
Department of Mathematics

Dynamical Systems Group


Computational Sciences Research Center

San Diego State University


San Diego, CA 92182-7720

http://www-rohan.sdsu.edu/jmahaffy

Spring 2010
Joe Mahaffy, hmahaffy@math.sdsu.edui
Multiple Integrals
Improper Integrals

Multiple Integrals; Improper Integrals

(1/25)

CSR in n-D
Non-Rectangular Domains

ZZ

f (x, y ) dx dy ,

where R = {(x, y ) : x [a, b], y [c, d]}.

We write

ZZ
I=

f (x, y ) dx dy =

b
a

Z
c

f (x, y ) dy dx,

and first apply CSR to approximate the integration in y treating


x as a constant.

Composite Simpsons Rule (CSR) is our favorite integration


scheme; we discuss multi-dimensional integration in that context.
Multiple Integrals; Improper Integrals

The integration techniques we have developed


previously can be adopted for multi-dimensional
integration in a straight-forward way.

Joe Mahaffy, hmahaffy@math.sdsu.edui

CSR in n-D
Non-Rectangular Domains

We divide the x-range [a, b] into an even


number nx of sub-intervals with nodes
spaced hx = (b a)/nx apart, and
the y -range [c, d] into an even number
ny of sub-intervals with nodes spaced
hy = (d c)/ny apart.

11111111
00000000
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
00000000
11111111
a

Good News:

(2/25)

Multi-Dimensional Composite Simpsons Rule

Very few interesting problems are one-dimensional, so we need


integration schemes for multiple integrals, i.e.

Multiple Integrals; Improper Integrals

Multiple Integrals
Improper Integrals

The World is not One-Dimensional

I=

Joe Mahaffy, hmahaffy@math.sdsu.edui

(3/25)

Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(4/25)

Multiple Integrals
Improper Integrals

CSR in n-D
Non-Rectangular Domains

Multiple Integrals
Improper Integrals

Composite Simpsons Rule in the y -coordinate


1

Apply Composite Simpsons Rule in the x-coordinate

Let yj = c + jhy , j = 0, 1, . . . , ny , then


Z

d
c

Now, we simply apply CSR in the x-coordinate, for each integral


in the expression...

ny /2

hy
f (x, y ) dy =
2f (x, y2j ) + 4f (x, y2j1 )
f (x, y0 ) f (x, yn ) +
3
j=1

(d c)hy4
180

4 f (x, y )

,
y 4

Then we apply the integral in the xcoordinate...


Z b
Z bZ d
Z b
hy
f (x, y ) dy dx =
f (x, y0 ) dx
f (x, yn ) dx
3
a
c
a
a

Z b
ny /2 Z b
X
f (x, y2j1 ) dx
+
f (x, y2j ) dx + 4
2
j=1

a
c)hy4

(d

180

Z
a

4 f (x, y )
y 4

Joe Mahaffy, hmahaffy@math.sdsu.edui


Multiple Integrals
Improper Integrals

d
c

f (x, y ) dy dx

nx /2
X
hx hy
2f (x2i , y0 ) + 4f (x2i1 , y0 )
f (x0 , y0 ) f (xn , y0 ) +
9
i=1

nx /2
X
2f (x2i , yn ) + 4f (x2i1 , yn )
f (x0 , yn ) f (xn , yn ) +
+

i=1

nx /2
X
2f (x2i , y2j ) + 4f (x2i1 , y2j )
2 f (x0 , y2j ) f (xn , y2j ) +
i=1
nx /2

j=1

+4 f (x0 , y2j1 ) f (xn , y2j1 ) +

2f (x2i , y2j1 ) + 4f (x2i1 , y2j1 )

i=1

dx,

Multiple Integrals; Improper Integrals

ny /2

b
a

for some y [c, d].


2

CSR in n-D
Non-Rectangular Domains

This looks somewhat painful, but do not despair!!! [First, a peek at the error...]

(5/25)

Joe Mahaffy, hmahaffy@math.sdsu.edui

CSR in n-D
Non-Rectangular Domains

Multiple Integrals; Improper Integrals

Multiple Integrals
Improper Integrals

2-Dimensional Composite Simpsons Rule The Error

(6/25)

CSR in n-D
Non-Rectangular Domains

Building 2-D CSR in a Comprehensible Way?


Consider the tensor product of the x- and y -stencils for CSR with
2 sub-intervals:

The error for the approximation is

4
(b a)(d c) 4 4 f
4 f
hx 4 (x , x ) + hy 4 (y , y )
E =
180
x
y

hx
3

for some (x , x ), (y , y ) R = [a, b] [c, d].

hy
3

Derivation of the error is left as an


exercise for the interested reader...

16

16

16

16

hx hy
9

Evaluate the function at the corresponding points, multiply by the


above weights, and sum 2-D CSR.

Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(7/25)

Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(8/25)

Multiple Integrals
Improper Integrals

CSR in n-D
Non-Rectangular Domains

Multiple Integrals
Improper Integrals

Building Higher-Dimensional Schemes

Building 2-D CSR in a Comprehensible Way? Example

9
hx hy

x4

y4

Using the same strategy, we can build a 3-D CSR-scheme

f (x, y ) dx dy

1 f (x0 , y0 ) + 4f (x1 , y0 ) + 2f (x2 , y0 ) + 4f (x3 , y0 ) + f (x4 , y0 ) +

4 f (x0 , y1 ) + 4f (x1 , y1 ) + 2f (x2 , y1 ) + 4f (x3 , y1 ) + f (x4 , y1 ) +

2 f (x0 , y2 ) + 4f (x1 , y2 ) + 2f (x2 , y2 ) + 4f (x3 , y2 ) + f (x4 , y2 ) +

4 f (x0 , y3 ) + 4f (x1 , y3 ) + 2f (x2 , y3 ) + 4f (x3 , y3 ) + f (x4 , y3 ) +

1 f (x0 , y4 ) + 4f (x1 , y4 ) + 2f (x2 , y4 ) + 4f (x3 , y4 ) + f (x4 , y4 )


x0

y0

CSR in n-D
Non-Rectangular Domains

hx =

x4 x 0
,
4

Joe Mahaffy, hmahaffy@math.sdsu.edui


Multiple Integrals
Improper Integrals

hy =

y4 y 0
.
4

Multiple Integrals; Improper Integrals

CSRxyz = CSRx CSRy CSRz .


Theres nothing unique about the usage of CSR. The same idea can be
used to build higher dimensional Gaussian Quadrature schemes. If we
have the stencils for the one-dimensional (Composite) Gaussian
Quadrature schemes in the x-, y - and z-directions (GQx , GQy , GQz ):
GQxyz = GQx GQy GQz .
If youre really twisted you could use different schemes in the different
coordinate directions, i.e.
NUMINTxyz = CSRx GQy Rombergz .
Needless to say, the error terms would get really interesting.

(9/25)

CSR in n-D
Non-Rectangular Domains

Joe Mahaffy, hmahaffy@math.sdsu.edui


Multiple Integrals
Improper Integrals

Integrating Outside the Box

Multiple Integrals; Improper Integrals

(10/25)

CSR in n-D
Non-Rectangular Domains

Dealing with Variable Integration Limits

The integration schemes we have discussed so far only works for


rectangular regions [a, b] [c, d]...
In calculus we compute integrals of this form:
Z

b
a

d(x)

c(x)

f (x, y ) dy dx

In order to numerically compute an integral of this type


Z

We can modify our integration schemes to deal with this type of


integrals.

b
a

d(x)

c(x)

f (x, y ) dy dx

we are going to use CSR with a fixed step size hx = (b a)/nx in


the x-direction, and variable step size hy = (d(x) c(x))/ny in
the y -direction.
Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(11/25)

Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(12/25)

Multiple Integrals
Improper Integrals

CSR in n-D
Non-Rectangular Domains

Multiple Integrals
Improper Integrals

Variable Integration Limits Example

Variable Integration Limits

For simplicity we apply straight-up one-step SR to


Z b Z d(x)
f (x, y ) dy dx
a

We can imagine how to extend to multiple dimensions, i.e.


Z

c(x)

and get
Z
a

d(x)

c(x)

hx
3

f (x, y ) dy dx

d(x0 )c(x0 )
c(x0 )+d(x0 )
f (x0 , c(x0 )) + 4f (x0 ,
) + f (x0 , d(x0 )) +
6
2

c(x1 )+d(x1 )
4(d(x1 )c(x1 ))
f (x1 , c(x1 )) + 4f (x1 ,
) + f (x1 , d(x1 )) +
6
2

d(x2 )c(x2 )
c(x2 )+d(x2 )
) + f (x2 , d(x2 )) ,
f (x2 , c(x2 )) + 4f (x2 ,
6
2

where x0 = a, x1 =

CSR in n-D
Non-Rectangular Domains

d(x) Z f (x,y )
c(x)

e(x,y )

g (x, y , z) dz dy dx.

Again, there nothing special about Simpsons Rule we can


attack variable integration limits with Gaussian Quadrature,
Trapezoidal Rule, or Booles Rule...
Note that there is nothing stopping us from using adaptive schemes
to find the integrals... but the complexity of the code grows!

a+b
, x2 = b.
2

Joe Mahaffy, hmahaffy@math.sdsu.edui


Multiple Integrals
Improper Integrals

Multiple Integrals; Improper Integrals

(13/25)

CSR in n-D
Non-Rectangular Domains

Multiple Integrals
Improper Integrals

Algorithm: Variable Limits Double Integral using CSR

(14/25)

Calculus Treasures
Taylor Expansions... Surprise!

Improper integrals:

[1] hx = (b-a)/n, ENDPTS=0, EVENPTS=0, ODDPTS=0


[2] FOR i = 0, 1, . . . , n
% CSR in x
x = a + i*hx
k1 = f(x,c(x)) + f(x,d(x))
% End terms
k2 = 0
% Even terms
k3 = 0
% Odd terms
hy = (d(x)-c(x))/n
FOR j = 1, 2, . . . , (m 1)
y = c(x)+j*hy
Q = f(x,y)
IF j EVEN: k2 += Q, ELSE: k3 += Q
END-FOR-j
L = hy*(k1 + 2*k2 + 4*k3)/3;
IF i is 0 OR n: ENDPTS += L
ELSEIF i EVEN:
EVENPTS += L
ELSEIF i ODD:
ODDPTS += L
END-FOR-i
INTAPPROX = hx*(ENDPTS+2*EVENPTS+4*ODDPTS)/3
Multiple Integrals; Improper Integrals

Multiple Integrals; Improper Integrals

Improper Integrals Introduction

Algorithm: Variable Limits Double Integral CSR

Joe Mahaffy, hmahaffy@math.sdsu.edui

Joe Mahaffy, hmahaffy@math.sdsu.edui

(15/25)

[1] Integrals over infinite intervals


Z
f (x) dx.
a

[2] Integrals with unbounded functions


Z

b
a

f (x)
dx.
(x a)p

Note: We can always transform [1][2]

Z 0
Z
t = x 1
f (x) dx =
=
t 2 f (t 1 ) dt
2 dx
dt
=
x
a
1/a
Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(16/25)

Multiple Integrals
Improper Integrals

Calculus Treasures
Taylor Expansions... Surprise!

Multiple Integrals
Improper Integrals

More Forgotten Calculus

Splitting the Integrand using Taylor Expansions

The integral

b
a

dx
(x a)p

Pd (x) =
We can now write
Z
Z b
f (x) dx =
a

then the improper integral


Z b
a

p (, 1),

d
X
k=0

Multiple Integrals; Improper Integrals

(17/25)

Calculus Treasures
Taylor Expansions... Surprise!

g (x) Pd (x)
dx =
(x a)p

Z
a

II/II

1
max |g (d+1) (x)|

(k + 1)! x[a,b]
=

b
a

Z
a

g (d+1) ((x))(x a)d+1


dx
(k + 1)!(x a)p

(x a)d+1p dx

Joe Mahaffy, hmahaffy@math.sdsu.edui

(18/25)

Calculus Treasures
Taylor Expansions... Surprise!

Numerical Approximation of the Remainder Term

Define: (Remove the singularity)

g (x) Pd (x)
(x a)p
G (x) =

x (a, b]
x = a.

j=1

What if we want to do better?

Add the CSR-approximation to


Multiple Integrals; Improper Integrals

Multiple Integrals; Improper Integrals

Apply: Composite Simpsons Rule

Z b
n/2
X
h
4G (x2j1 ) + 2G (x2j ) .
G (x) dx G (x0 ) G (xn ) +
3
a

g(d+1) ()
(b a)d+2p .
(k + 1)! (d + 2 p)

Joe Mahaffy, hmahaffy@math.sdsu.edui

Pd (x)
dx,
(x a)p

To get a more accurate approximation to the integral, we compute the


numerical approximation of the remainder term:
Z b
g (x) Pd (x)
dx.
(x a)p
a

g (k) (a)
(b a)k+1p ,
k!(k + 1 p)

Rd (x)
dx =
(x a)p

k=0

Multiple Integrals
Improper Integrals

then the approximation error is bounded by:


Z

where the last integral is easy to find, since Pd (x) is a polynomial:


d
d Z b (k)
X
X
g (a)
g (k) (a)
(x a)kp dx =
(b a)k+1p
k!
k!(k
+
1

p)
a

Splitting the Integrand using Taylor Expansions

f (x) dx

g (x) Pd (x)
dx +
(x a)p

k=0

Multiple Integrals
Improper Integrals

g C [a, b]

f (x) dx, exists.

Joe Mahaffy, hmahaffy@math.sdsu.edui

d
X
g (k) (a)(x a)k
.
k!
k=0

If f (x) can be written on the form


g (x)
f (x) =
,
(x a)p

I/II

Assuming that g C d+1 [a, b], for some d Z+ , the Taylor


polynomial of degree d is

converges if and only if p (, 1), and


Z b
(b a)1p
dx
=
.
p
1p
a (x a)

If we let

Calculus Treasures
Taylor Expansions... Surprise!

(19/25)

Pd

g (k) (a)
k=0 k!(k+1p) (b

Joe Mahaffy, hmahaffy@math.sdsu.edui

a)k+1p .

Multiple Integrals; Improper Integrals

(20/25)

Multiple Integrals
Improper Integrals

Calculus Treasures
Taylor Expansions... Surprise!

Multiple Integrals
Improper Integrals

Example#1

I/III
Z
0

Z
0

x 1/2 + x 1/2 +

x 3/2 x 5/2 x 7/2


+
+
dx
2
6
24

Multiple Integrals; Improper Integrals

Result

(21/25)

III/III

The P6 (x)-only-error is comparable with the P4 (x)+CSR-error:


1
= 0.000026455.
7! 7.5
Multiple Integrals; Improper Integrals

x = 0.

ex
dx 2.923544974 + 0.0017691 = 2.9253141
x1/2

Joe Mahaffy, hmahaffy@math.sdsu.edui


Multiple Integrals
Improper Integrals

Since |G (4) (x)| < 1 on (0, 1], the error from CSR is bounded by
1
1
4 = 0.0000217.
180 4
The error bound for the Taylor-only approximation is bounded by
1
= 0.00151515
5! 5.5
R
If, instead of adding the CSR-approximation of G (x) dx, we used
P5 (x), the error bound for that Taylor-only approximation would be
1
= 0.00021044.
6! 6.5

Joe Mahaffy, hmahaffy@math.sdsu.edui

Calculus Treasures
Taylor Expansions... Surprise!

Example#1

x (0, 1]

Multiple Integrals
Improper Integrals

G (x) dx, where

Hence,

2 2
2
2
2
+ +
+
+
2.923544974
1 3 2 5 6 7 24 9

Joe Mahaffy, hmahaffy@math.sdsu.edui

1
0 + 4 0.0000170 + 2 0.00413 + 4 0.0026026
G (x) dx
43
0

+0.0099485 = 0.0017691.

so
P4 (x)
dx =
x 1/2

R1

x
e P4 (x)
x 1/2
G (x) =

x2 x3 x4
+
+ ,
P4 (x) = 1 + x +
2
6
24
1

II/III

ex
dx.
x 1/2

The fourth order Taylor polynomial is

Example#1
Next, we apply CSR with h = 1/4 to

We want to compute

Calculus Treasures
Taylor Expansions... Surprise!

(22/25)

Calculus Treasures
Taylor Expansions... Surprise!

Example#2

I/II

We are going to approximate the integral



Z
1
1
dx.
sin
3/2
x
x
1
A quick change of variables t = x 1 gives us
Z 1
t 1/2 sin(t) dt.
0

The sixth Taylor polynomial P6 (t) for sin(t) about t = 0 is


1
1 5
1
P6 (t) = t t 3 +
t , |R6 (t)|
= 0.00019841
6
120
7!
Z 1
Z 1
1
1 9/2
1/2
t 1/2 t 5/2 +
t
P6 (t) dt =
t dt
6
120
0
0
=

(23/25)

Multiple Integrals; Improper Integrals

2
2
2

+
= 0.62056277
3 7 6 11 120

Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(24/25)

Multiple Integrals
Improper Integrals

Calculus Treasures
Taylor Expansions... Surprise!

Example#2

II/II

We define

sin(t) P6 (t) t (0, 1]


t 1/2
G (t) =

0
t = 0,
R1
and apply CSR with h = 1/32 to 0 G (t) dt to get
Result
Z
1

1
x3/2


1
dx
sin
x

0.62056277 0.0000261672790305 = 0.62053660 . . .


which is accurate to within 108 .
Joe Mahaffy, hmahaffy@math.sdsu.edui

Multiple Integrals; Improper Integrals

(25/25)

You might also like