• 沒有找到結果。

Numerical Differentiation and Integration

N/A
N/A
Protected

Academic year: 2022

Share "Numerical Differentiation and Integration"

Copied!
55
0
0

加載中.... (立即查看全文)

全文

(1)

師大

Numerical Differentiation and Integration

Tsung-Ming Huang

Department of Mathematics National Taiwan Normal University, Taiwan

January 1, 2008

(2)

師大

Outline

1 Numerical Differentiation

2 Richardson Extrapolation Method

3 Elements of Numerical Integration Newton-Cotes Formulas

Composite Newton-Cotes Forumlas

(3)

師大

Numerical Differentiation

f0(x0) = lim

h→0

f (x0+ h) − f (x0)

h .

Question How accurate is

f (x0+ h) − f (x0)

h ?

Suppose a given function f has continuous first derivative and f00 exists.

From Taylor’s theorem

f (x + h) = f (x) + f0(x)h + 1

2f00(ξ)h2, where ξ is between x and x + h, one has

f0(x) = f (x + h) − f (x)

h − h

2f00(ξ) = f (x + h) − f (x)

h + O(h).

(4)

師大

Hence it is reasonable to use the approximation f0(x) ≈ f (x + h) − f (x)

h

which is called forward finite difference, and the error involved is

|e| = h

2|f00(ξ)| ≤ h 2 max

t∈(x,x+h)|f00(t)|.

Similarly one can derive the backward finite difference approximation f0(x) ≈ f (x) − f (x − h)

h (1)

which has the same order of truncation error as the forward finite difference scheme.

(5)

師大

The forward difference is an O(h) scheme. An O(h2) scheme can also be derived from the Taylor’s theorem

f (x + h) = f (x) + f0(x)h +1

2f00(x)h2+1

6f0001)h3 f (x − h) = f (x) − f0(x)h +1

2f00(x)h2−1

6f0002)h3, where ξ1 is between x and x + h and ξ2 is between x and x − h. Hence

f (x + h) − f (x − h) = 2f0(x)h +1

6[f0001) + f0002)]h3 and

f0(x) = f (x + h) − f (x − h)

2h − 1

12[f0001) + f0002)]h2 Let

M = max

z∈[x−h,x+h]f000(z) and m = min

z∈[x−h,x+h]f000(z).

(6)

師大

If f000 is continuous on [x − h, x + h], then by the intermediate value theorem, there exists ξ ∈ [x − h, x + h] such that

f000(ξ) = 1

2[f0001) + f0002)].

Hence

f0(x) = f (x + h) − f (x − h)

2h −1

6f000(ξ)h2 = f (x + h) − f (x − h)

2h + O(h2).

This is called center difference approximation and the truncation error is

|e| = h2 6 f000(ξ)

Similarly, we can derive an O(h2) scheme from Taylor’s theorem for f00(x) f00(x) = f (x + h) − 2f (x) + f (x − h)

h2 − 1

12f(4)(ξ)h2, where ξ is between x − h and x + h.

(7)

師大

Polynomial Interpolation Method

Suppose that (x0, f (x0)), (x1, f (x1)) · · · , (xn, f (xn) have been given, we apply the Lagrange polynomial interpolation scheme to derive

P (x) =

n

X

i=0

f (xi)Li(x), where

Li(x) =

n

Y

j=0,j6=i

x − xj xi− xj. Since f (x) can be written as

f (x) =

n

X

i=0

f (xi)L(x) + 1

(n + 1)!f(n+1)x)w(x), where

w(x) =

n

Y

j=0

(x − xj),

(8)

師大

we have,

f0(x) = X

i=0

nf (xi)L0i(x) + 1

(n + 1)!f(n+1)x)w0(x)

+ 1

(n + 1)!w(x) d

dxf(n+1)x).

Note that

w0(x) =

n

X

j=0 n

Y

i=0,i6=j

(x − xi).

Hence a reasonable approximation for the first derivative of f is f0(x) ≈

n

X

i=0

f (xi)L0i(x).

When x = xk for some 0 ≤ k ≤ n,

w(xk) = 0 and w0(xk) =

n

Y

i=0,i6=k

(xk− xi).

(9)

師大

Hence f0(xk) =

n

X

i=0

f (xi)L0i(xk) + 1

(n + 1)!f(n+1)x)

n

Y

i=0,i6=k

(xk− xi), (2)

which is called an (n + 1)-point formula to approximate f0(x).

• Three Point Formulas Since

L0(x) = (x − x1)(x − x2) (x0− x1)(x0− x2) we have

L00(x) = 2x − x1− x2 (x0− x1)(x0− x2). Similarly,

L01(x) = 2x − x0− x2

(x1− x0)(x1− x2) and L02(x) = 2x − x0− x1 (x2− x0)(x2− x1).

(10)

師大

Hence

f0(xj) = f (x0)

 2xj − x1− x2 (x0− x1)(x0− x2)



+ f (x1)

 2xj− x0− x2 (x1− x0)(x1− x2)



+ f (x2)

 2xj − x0− x1 (x2− x0)(x2− x1)

 +1

6f(3)j)

2

Y

k=0,k6=j

(xj− xk),

for each j = 0, 1, 2. Assume that

x1 = x0+ h and x2 = x0+ 2h, for some h 6= 0.

Then

f0(x0) = 1 h



−3

2f (x0) + 2f (x1) −1 2f (x2)

 +h2

3 f(3)0), f0(x1) = 1

h



−1

2f (x0) +1 2f (x2)



−h2

6 f(3)1), f0(x2) = 1

h

 1

2f (x0) − 2f (x1) +3 2f (x2)

 +h2

3 f(3)2).

(11)

師大

That is

f0(x0) = 1 h



−3

2f (x0) + 2f (x0+ h) −1

2f (x0+ 2h)

 +h2

3 f(3)0), f0(x0+ h) = 1

h



−1

2f (x0) +1

2f (x0+ 2h)



−h2

6 f(3)1), (3) f0(x0+ 2h) = 1

h

 1

2f (x0) − 2f (x0+ h) +3

2f (x0+ 2h)

 +h2

3 f(3)2).(4) Using the variable substitution x0 for x0+ h and x0+ 2h in (3) and (4), respectively, we have

f0(x0) = 1

2h[−3f (x0) + 4f (x0+ h) − f (x0+ 2h)] +h2

3 f(3)0),(5) f0(x0) = 1

2h[−f (x0− h) + f (x0+ h)] − h2

6 f(3)1), f0(x0) = 1

2h[f (x0− 2h) − 4f (x0− h) + 3f (x0)] + h2

3 f(3)2). (6) Note that (6) can be obtained from (5) by replacing h with −h.

(12)

師大

• Five-point Formulas

f0(x0) = 1

12h[f (x0− 2h) − 8f (x0− h) + 8f (x0+ h) − f (x0+ 2h)]

+ h4

30f(5)(ξ),

where ξ ∈ (x0− 2h, x0+ 2h) and f0(x0) = 1

12h[−25f (x0) + 48f (x0+ h) − 36f (x0+ 2h) + 16f (x0+ 3h) − 3f (x0+ 4h)] +h4

5 f(5)(ξ), where ξ ∈ (x0, x0+ 4h).

(13)

師大

Round-off Error

Consider

f0(x0) = 1

2h[−f (x0− h) + f (x0+ h)] − h2

6 f(3)1),

where h62f(3)1) is called truncation error. Let ˜f (x0+ h) and ˜f (x0− h) be the computed values of f (x0+ h) and f (x0− h), respectively. Then

f (x0+ h) = ˜f (x0+ h) + e(x0+ h) and

f (x0− h) = ˜f (x0− h) + e(x0− h).

Therefore, the total error in the approximation f0(x0) −f (x˜ 0+ h) − ˜f (x0− h)

2h = e(x0+ h) − e(x0− h)

2h − h2

6 f(3)1) is due in part to round-off error and in the part to truncation error.

(14)

師大

Assume that

|e(x0± h)| ≤ ε and |f(3)1)| ≤ M.

Then

f0(x0) −f (x˜ 0+ h) − ˜f (x0− h) 2h

≤ ε 2h+h2

6 M ≡ e(h).

Note that e(h) attains its minimum at h =p3ε/M .3

(15)

師大

Richardson’s Extrapolation

Suppose ∀h 6= 0 we have a formula N1(h) that approximates an unknown value M

M − N1(h) = K1h + K2h2+ K3h3+ · · · , (7) for some unknown constants K1, K2, K3, . . .. If K1 6= 0, then the

truncation error is O(h). For example, f0(x) − f (x + h) − f (x)

h = −f00(x)

2! h −f000(x)

3! h2−f(4)(x)

4! h3− · · · . Goal

Find an easy way to produce formulas with a higher-order truncation error.

Replacing h in (7) by h/2, we have M = N1

 h 2

 + K1

h 2 + K2

h2 4 + K3

h3

8 + · · · . (8)

(16)

師大

Subtracting (7) with twice (8), we get M = N2(h) −K2

2 h2−3K3

4 h3− · · · , (9)

where

N2(h) = 2N1 h 2



− N1(h) = N1 h 2

 +

 N1 h

2



− N1(h)

 , which is an O(h2) approximation formula.

Replacing h in (9) by h/2, we get M = N2 h

2



−k2

8 h2−3K3

32 h3− · · · . (10) Subtracting (9) from 4 times (10) gives

3M = N2 h 2



− N2(h) +3K3

8 h3+ · · · , which implies that

M =

 N2

 h 2



+N2(h/2) − N2(h) 3

 +K3

8 h3+ · · · ≡ N3(h) +K3

8 h3+ · · · .

(17)

師大

Using induction, M can be approximated by M = Nm(h) + O(hm), where

Nm(h) = Nm−1 h 2



+Nm−1(h/2) − Nm−1(h) 2m−1− 1 . Centered difference formula. From the Taylor’s theorem f (x + h) = f (x) + hf0(x) +h2

2!f00(x) + h3

3!f000(x) + h4

4!f(4)(x) + h5

5!f(5)(x) + h6

6!f(6)(x) + · · · f (x − h) = f (x) − hf0(x) +h2

2!f00(x) − h3

3!f000(x) + h4

4!f(4)(x) − h5

5!f(5)(x) + h6

6!f(6)(x) + · · · we have

f (x + h) − f (x − h) = 2hf0(x) + 2h3

3! f000(x) +2h5

5! f(5)(x) + · · · ,

(18)

師大

and, consequently,

f0(x0) = f (x0+ h) − f (x0− h)

2h − h2

3!f000(x0) +h4

5!f(5)(x0) + · · ·

 ,

≡ N1(h) − h2

3!f000(x0) +h4

5!f(5)(x0) + · · ·



. (11)

Replacing h in (11) by h/2 gives f0(x0) = N1 h

2



−h2

24f000(x0) − h4

1920f(5)(x0) − · · · . (12) Subtracting (11) from 4 times (12) gives

f0(x0) = N2(h) + h4

480f(5)(x0) + · · · , where

N2(h) = 1 3



4N1 h 2



− N1(h)



= N1 h 2



+ N1(h/2) − N1(h)

3 .

(19)

師大

In general,

f0(x0) = Nj(h) + O(h2j) with

Nj(h) = Nj−1 h 2



+Nj−1(h/2) − Nj−1(h) 4j−1− 1 .

Example

Suppose that x0 = 2.0, h = 0.2 and f (x) = xex. Compute an

approximated value of f0(2.0) = 22.16716829679195 to six decimal places.

Solution. By centered difference formula, we have N1(0.2) = f (0.2 + h) − f (0.2 − h)

2h = 22.414160,

N1(0.1) = f (0.1 + h) − f (0.1 − h)

2h = 22.228786.

(20)

師大

It implies that

N2(0.2) = N1(0.1) +N1(0.1) − N1(0.2)

3 = 22.166995

which does not have six decimal digits. Adding N1(0.05) = 22.182564, we get

N2(0.1) = N1(0.05) +N1(0.05) − N1(0.1)

3 = 22.167157

and

N3(0.2) = N2(0.1) +N2(0.1) − N2(0.2)

15 = 22.167168

which contains six decimal digits.

(21)

師大

O(h) O(h2) O(h3) O(h4) 1: N1(h) = N (h)

2: N1(h/2) = N (h/2) 3: N2(h)

4: N1(h/4) = N (h/4) 5: N2(h/2) 6: N3(h)

7: N1(h/8) = N (h/8) 8: N2(h/4) 9: N3(h/2) 10: N4(h)

(22)

師大

Elements of Numerical Integration

The basic method involved in approximating the integration Z b

a

f (x) dx, (13)

is called numerical quadrature and uses a sum of the type Z b

a

f (x) dx ≈

n

X

i=0

cif (xi). (14)

The method of quadrature in this section is based on the polynomial interpolation. We first select a set of distinct nodes {x0, x1, . . . , xn} from the interval [a, b]. Then the Lagrange polynomial

Pn(x) =

n

X

i=0

f (xi)Li(x) =

n

X

i=0

f (xi)

n

Y

j=0

j6=i

x − xj

xi− xj

is used to approximate f (x). With the error term we have

(23)

師大

f (x) = Pn(x) + En(x) =

n

X

i=0

f (xi)Li(x) + f(n+1)x) (n + 1)!

n

Y

i=0

(x − xi), where ζx∈ [a, b] and depends on x, and

Z b

a

f (x) dx = Z b

a

Pn(x) dx + Z b

a

En(x) dx

=

n

X

i=0

f (xi) Z b

a

Li(x) dx + 1 (n + 1)!

Z b a

f(n+1)x)

n

Y

i=0

(x − xi) dx.(15) The quadrature formula is, therefore,

Z b a

f (x) dx ≈ Z b

a

Pn(x) dx =

n

X

i=0

f (xi) Z b

a

Li(x) dx ≡

n

X

i=0

cif (xi), (16) where

ci = Z b

a

Li(x) dx = Z b

a n

Y

j=0

j6=i

x − xj

xi− xj dx. (17)

(24)

師大

Moreover, the error in the quadrature formula is given by

E = 1

(n + 1)!

Z b

a

f(n+1)x)

n

Y

i=0

(x − xi) dx, (18) for some ζx ∈ [a, b].

Let us consider formulas produced by using first and second Lagrange polynomials with equally spaced nodes. This gives the Trapezoidal rule and Simpson’s rule, respectively.

Trapezoidal rule: Let x0 = a, x1 = b, h = b − a and use the linear Lagrange polynomial:

P1(x) = (x − x1)

(x0− x1)f (x0) + (x − x0) (x1− x0)f (x1).

Then Z b

a

f (x)dx = Z x1

x0

 (x − x1)

(x0− x1)f (x0) + (x − x0) (x1− x0)f (x1)

 dx +1

2 Z x1

x0

f00(ζ(x))(x − x0)(x − x1)dx. (19)

(25)

師大

Theorem (Weighted Mean Value Theorem for Integrals) Suppose f ∈ C[a, b], the Riemann integral of g(x)

Z b

a

g(x)dx = lim

max 4xi→0 n

X

i=1

g(xi)4xi,

exists and g(x) does not change sign on [a, b]. Then ∃ c ∈ (a, b) with Z b

a

f (x)g(x)dx = f (c) Z b

a

g(x)dx.

Since (x − x0)(x − x1) does not change sign on [x0, x1], by the Weighted Mean Value Theorem, ∃ ζ ∈ (x0, x1) such that

Z x1

x0

f00(ζ(x))(x − x0)(x − x1)dx = f00(ζ) Z x1

x0

(x − x0)(x − x1)dx

= f00(ζ) x3

3 − x1+ x0

2 x2+ x0x1x

x1

x0

= −h3 6 f00(ζ).

(26)

師大

Consequently, Eq. (19) implies that Z b

a

f (x)dx =  (x − x1)2

2(x0− x1)f (x0) + (x − x0)2 2(x1− x0)f (x1)

x1

x0

−h3 12f00(ζ)

= x1− x0

2 [f (x0) + f (x1)] − h3 12f00(ζ)

= h

2[f (x0) + f (x1)] − h3 12f00(ζ), which is called the Trapezoidal rule.

(27)

師大

If we choose x0= a, x1= 12(a + b), x2 = b, h = (b − a)/2, and the second order Lagrange polynomial

P2(x) = f (x0) (x − x1)(x − x2)

(x0− x1)(x0− x2) + f (x1) (x − x0)(x − x2) (x1− x0)(x1− x2) +f (x2) (x − x0)(x − x1)

(x2− x0)(x2− x1) to interpolate f (x), then

(28)

師大

Z b a

f (x)dx = Z x2

x0

 (x − x1)(x − x2)

(x0− x1)(x0− x2)f (x0) + (x − x0)(x − x2) (x1− x0)(x1− x2)f (x1) + (x − x0)(x − x1)

(x2− x0)(x2− x1)f (x2)

 dx +

Z x2

x0

(x − x0)(x − x1)(x − x2)

6 f(3)(ζ(x))dx.

Since, letting x = x0+ th, Z x2

x0

(x − x1)(x − x2)

(x0− x1)(x0− x2)dx = h Z 2

0

t − 1

0 − 1 · t − 2 0 − 2dt

= h

2 Z 2

0

(t2− 3t + 2) dt = h 3, Z x2

x0

(x − x0)(x − x2)

(x1− x0)(x1− x2)dx = h Z 2

0

t − 0

1 − 0 · t − 2 1 − 2dt

= −h Z 2

0

(t2− 2t) dt = 4h 3 ,

(29)

師大

Z x2

x0

(x − x0)(x − x1)

(x2− x0)(x2− x1)dx = h Z 2

0

t − 0

2 − 0 · t − 1 2 − 1dt

= h

2 Z 2

0

(t2− t) dt = h 3, it implies that

Z b

a

f (x)dx = h 1

3f (x0) +4

3f (x1) +1 3f (x2)



+ Z x2

x0

(x − x0)(x − x1)(x − x2)

6 f(3)(ζ(x))dx, which is called the Simpson’s rule.

Deriving Simpson’s rule in this way, however, provides only an O(h4) error term involving f(3). A higher order error analysis can be derived by expanding f in the third Taylor’s formula about x1. Then for each x ∈ [a, b], there exists ζx∈ (a, b) such that

f (x) = f (x1) + f0(x1)(x − x1) + f00(x1)

2 (x − x1)2 +f000(x1)

6 (x − x1)3+f(4)x)

24 (x − x1)4.

T.M. Huang (Nat. Taiwan Normal Univ.) Numerical Diff. & integ. January 1, 2008 29 / 31

(30)

師大

Then Z b

a

f (x) dx =



f (x1)(x − x1) +f0(x1)

2 (x − x1)2+f00(x1)

6 (x − x1)3 +f000(x1)

24 (x − x1)4



b

a

+ 1 24

Z b a

f(4)x)(x − x1)4dx.

Note that (b − x1) = h, (a − x1) = −h, and since (x − x1)4 does not change sign in [a, b], by the Weighted Mean-Value Theorem for Integral, there exists ξ1 ∈ (a, b) such that

Z b a

f(4)x)(x − x1)4dx = f(4)1) Z b

a

(x − x1)4dx = 2f(4)1) 5 h5. Consequently,

Z b a

f (x) dx = 2f (x1)h +f00(x1)

3 h3+f(4)1) 60 h5.

(31)

師大

Finally we replace f00(x1) by the central finite difference formulation f00(x1) = f (x0) − 2f (x1) + f (x2)

h2 −f(4)2) 12 h2, for some ξ2 ∈ (a, b), to obtain

Z b a

f (x) dx = 2hf (x1) +h

3(f (x0) − 2f (x1) + f (x2))

−f(4)2)

36 h5+f(4)1) 60 h5

= h 1

3f (x0) +4

3f (x1) +1 3f (x2)



+ 1 90

 3

2f(4)1) −5

2f(4)2)

 h5. It can show that there exists ξ ∈ (a, b) such that

Z b a

f (x) dx = h

3 [f (x0) + 4f (x1) + f (x2)] − f(4)(ξ) 90 h5. This gives the Simpson’s rule formulation.

(32)

師大

If |f(n+1)(x)| ≤ M on [a, b], then

Z b a

f (x) dx −

n

X

i=0

cif (xi)

≤ M

(n + 1)!

Z b a

n

Y

i=0

(x − xi) dx. (20) The choice of nodes that makes the right-hand side of this error bound as small as possible is know to be

xi = a + b

2 +b − a

2 cos (i + 1)π n + 2



, i = 0, 1, . . . , n. (21) Of course, a polynomial interpolation to f can be obtained in other ways, for example, polynomial in Newton’s form using divided-difference method,

Pn(x) = f (x0) +

n

X

i=1

f [x0, x1, . . . , xi]

i−1

Y

j=0

(x − xj)

where f [x0, x1, . . . , xi] are evaluated with the divided difference algorithm.

Then Z b

a

f (x) dx ≈ f (x0)(b − a) +

n

Xf [x0, x1, . . . , xi] Z b

a i−1

Y(x − xj) dx. (22)

(33)

師大

The standard derivation of quadrature error formulas is based on determining the class of polynomials for which theses formulas produce exact results. The next definition is used to facilitate the discussion of this derivation.

Definition

The degree of accuracy, or precision, of a quadrature formula is the largest positive integer n such that the formula is exact for xk, when

k = 0, 1, . . . , n.

The definition implies that the degree of accuracy of a quadrature formula is n if and only if the error E = 0 for all polynomials P (x) of degree less than or equal to n, but E 6= 0 for some polynomials of degree greater than n.

A quadrature formula of the form (14) is called a Newton-Cotes formula if the nodes {x0, x1, . . . , xn} are equally spaced. Consider a uniform

partition of the closed interval [a, b] by

xi= a + ih, i = 0, 1, . . . , n, h = b − a n ,

(34)

師大

where n is a positive integer and h is called the step length. By introduction a new variable t such that x = a + ht, the fundamental Lagrange polynomial becomes

Li(x) =

n

Y

j=0

j6=i

x − xj

xi− xj =

n

Y

j=0

j6=i

a + ht − a − jh a + ih − a − jh =

n

Y

j=0

j6=i

t − j

i − j ≡ ϕi(t).

Therefore, the integration (17) gives

ci = Z b

a

Li(x) dx = Z n

0

ϕi(t)h dt = h Z n

0 n

Y

j=0

j6=i

t − j

i − j dt, (23)

and the general Newton-Cotes formula has the form Z b

a

f (x) dx = h

n

X

i=0

f (xi) Z n

0 n

Y

j=0

j6=i

t − j

i − j dt+ 1 (n + 1)!

Z b a

f(n+1)x)

n

Y

i=0

(x−xi) dx.

(24)

(35)

師大

The simplest case is to choose n = 1, x0 = a, x1 = b, h = b − a, and use the linear Lagrange polynomial

P1(x) = f (x0)x − x1

x0− x1 + f (x1) x − x0

x1− x0 = f (a)x − b

a − b + f (b)x − a b − a. to interpolate f (x). Then

c0= h Z 1

0

t − 1

0 − 1dt = h

2, c1 = h Z 1

0

t − 0

1 − 0dt = h 2, and

Z b a

P1(x) dx = c0f (x0) + c1f (x1) = h

2[f (a) + f (b)] .

Since (x − x0)(x − x1) = (x − a)(x − b) does not change sign on [a, b], by the Weighted Mean-Value Theorem for integrals, there exists some

(36)

師大

ξ ∈ (a, b) such that Z b

a

f00x)(x − x0)(x − x1) dx = f00(ξ) Z b

a

(x − x0)(x − x1) dx

= f00(ξ) Z b

a

(x − a)(x − b) dx

= f00(ξ) 1 3x3−1

2(a + b)x2+ abx



b

a

= −1

6f00(ξ)(b − a)3= −1

6f00(ξ)h3. Consequently,

Z b a

f (x) dx = h

2 [f (a) + f (b)] −h3 12f00(ξ).

This gives the so-called Trapezoidal rule.

Trapezoidal Rule:

Z b

f (x) dx = 1

(b − a) [f (a) + f (b)] − h3

f00(ξ), (25)

(37)

師大

where h = b − a and ξ ∈ (a, b).

It is evident that the error term of the Trapezoidal rule is O(h3). Since the rule involves f00, it gives the exact result when applied to any function whose second derivative is identically zero, e.g., any polynomial of degree 1 or less. Hence the degree of accuracy of Trapezoidal rule is one.

If we choose n = 2, x0 = a, x1 = 12(a + b), x2 = b, h = (b − a)/2, and the second order Lagrange polynomial

P2(x) = f (x0) (x − x1)(x − x2)

(x0− x1)(x0− x2)+f (x1) (x − x0)(x − x2)

(x1− x0)(x1− x2)+f (x2) (x − x0)(x − x1) (x2− x0)(x2− x1) to interpolate f (x), then

c0 = h Z 2

0

t − 1

0 − 1 · t − 2

0 − 2dt = h 2

Z 2 0

(t2− 3t + 2) dt = h 3, c1 = h

Z 2 0

t − 0

1 − 0 · t − 2

1 − 2dt = −h Z 2

0

(t2− 2t) dt = 4h 3 , c2 = h

Z 2 0

t − 0

2 − 0 · t − 1

2 − 1dt = h 2

Z 2 0

(t2− t) dt = h 3,

(38)

師大

and Z b

a

P2(x) dx = c0f (x0)+c1f (x1)+c2f (x2) = h 1

3f (a) +4

3f (a + b 2 ) +1

3f (b)



gives the so-called Simpson’s rule. Deriving the formulation this way, however, the error term

1 6

Z b a

f(3)x)(x − x0)(x − x1)(x − x2) dx

provides only an O(h4) formulation involving f(3). A higher order error analysis can be derived by expanding f in the third Taylor’s formula about x1. Then for each x ∈ [a, b], there exists ζx∈ (a, b) such that

f (x) = f (x1)+f0(x1)(x−x1)+f00(x1)

(x−x1)2+f000(x1)

(x−x1)3+f(4)x)

(x−x1)4.

(39)

師大

Then Z b

a

f (x) dx =



f (x1)(x − x1) +f0(x1)

2 (x − x1)2+f00(x1)

6 (x − x1)3+ f000(x1)

24 (x − x1)4



b

a

+ 1 24

Z b a

f(4)x)(x − x1)4dx.

Note that (b − x1) = h, (a − x1) = −h, and since (x − x1)4 does not change sign in [a, b], by the Weighted Mean-Value Theorem for Integral, there exists ξ1 ∈ (a, b) such that

Z b

a

f(4)x)(x − x1)4dx = f(4)1) Z b

a

(x − x1)4dx = 2f(4)1) 5 h5. Consequently,

Z b a

f (x) dx = 2f (x1)h +f00(x1)

3 h3+f(4)1) 60 h5. Finally we replace f00(x1) by the central finite difference formulation

f00(x1) = f (x0) − 2f (x1) + f (x2)

h2 −f(4)2) 12 h2,

(40)

師大

for some ξ2 ∈ (a, b), to obtain Z b

a

f (x) dx = 2hf (x1) +h

3(f (x0) − 2f (x1) + f (x2)) − f(4)2)

36 h5+f(4)1) 60 h5

= h 1

3f (x0) +4

3f (x1) +1 3f (x2)

 + 1

90

 3

2f(4)1) −5

2f(4)2)

 h5.

By letting f (x) = x4, one can show that there exists ξ ∈ (a, b) such that Z b

a

f (x) dx = h 1

3f (x0) +4

3f (x1) +1 3f (x2)



+f(4)(ξ) 90 h5. This gives the Simpson’s rule formulation.

Simpson’s Rule:

Z b a

f (x) dx = b − a 2

  1

3f (a) +4

3f (a + b 2 ) +1

3f (b)



+f(4)(ξ)

90 h5, (26) for some ξ ∈ (a, b). The Simpson’s rule is an O(h5) scheme and the degree of accuracy is three.

(41)

師大

The Trapezoidal and Simpson’s rules are examples of a class of methods known as closed Newton-Cotes formula. The (n + 1)-point closed Newton-Cotes method uses nodes xi= a + ih, for i = 0, 1, . . . , n, where h = (b − a)/n. Note that both endpoints, a = x0 and b = xn, of the closed interval [a, b] are included as nodes. The following theorem details the Newton-Cotes formulas and the associated error analysis.

(42)

師大

Theorem (Closed Newton-Cotes Formulas)

For a given function f (x) and closed interval [a, b], the (n + 1)-point closed Newton-Cotes method uses nodes

xi= a + ih, i = 0, 1, . . . , n, h = b − a n . If n is even and f ∈ Cn+2[a, b], then

Z b a

f (x) dx = h

n

X

i=0

αif (xi) +hn+3f(n+2)(ξ) (n + 2)!

Z n 0

t2(t − 1) · · · (t − n) dt, (27) and if n is odd and f ∈ Cn+1[a, b], then

Z b a

f (x) dx = h

n

X

i=0

αif (xi) +hn+2f(n+1)(ξ) (n + 1)!

Z n 0

t(t − 1) · · · (t − n) dt, (28) where ξ ∈ (a, b) and

αi = Z n

0 n

Y

j=0

j6=i

t − j

i − j dt, i = 0, 1, . . . , n. (29)

Consequently, the degree of accuracy is n + 1 when n is an even integer,

T.M. Huang (Nat. Taiwan Normal Univ.) Numerical Diff. & integ. January 1, 2008 31 / 31

(43)

師大

The weights αi in the Newton-Cotes formula has the property

n

X

i=0

αi = n. (30)

This can be shown by applying the formula to f (x) = 1 with interpolating polynomial Pn(x) = 1. Let s be the common denominator of αi, that is,

αi = σi

s (⇒ σi = sαi)

such that σi are integers, then the formulation for approximating the definite integral can be expressed as

Z b a

f (x) dx ≈ h

n

X

i=0

αif (xi) = h s

n

X

i=0

σif (xi). (31)

Some of the most common closed Newton-Cotes formulas with their error terms are listed in the following table.

(44)

師大

Name n s σi Error

Trapezoidal rule 1 2 1, 1 −121 f(2)(ξ)h3

Simpson’s rule 2 3 1, 4, 1 −901 f(4)(ξ)h5

3/8-rule 3 83 1, 3, 3, 1 −803 f(4)(ξ)h5

Milne’s rule 4 452 7, 32, 12, 32, 7 −9458 f(6)(ξ)h7 5 2885 19, 75, 50, 50, 75, 19 −12096275 f(6)(ξ)h7 Weddle’s rule 6 140 41, 216, 27, 272, 27, 216, 41 −14009 f(8)(ξ)h9 Another class of Newton-Cotes formulas is the open Newton-Cotes

formulas in which the nodes

xi = x0+ ih, i = 0, 1, . . . , n, where x0 = a + h and h = b − a n + 2, are used. This implies that xn= b − h, and the endpoints, a and b, are not used. Hence we label a = x−1 and b = xn+1. The following theorem summarizes the open Newton-Cotes formulas.

(45)

師大

Theorem (Open Newton-Cotes Formulas)

For a given function f (x) and closed interval [a, b], the (n + 1)-point open Newton-Cotes method uses nodes

xi = x0+ ih, i = 0, 1, . . . , n, where x0 = a + h and h = b − a n + 2. If n is even and f ∈ Cn+2[a, b], then

Z b a

f (x) dx = h

n

X

i=0

αif (xi) +hn+3f(n+2)(ξ) (n + 2)!

Z n+1

−1

t2(t − 1) · · · (t − n) dt, (32) and if n is odd and f ∈ Cn+1[a, b], then

Z b a

f (x) dx = h

n

X

i=0

αif (xi) +hn+2f(n+1)(ξ) (n + 1)!

Z n+1

−1

t(t − 1) · · · (t − n) dt, (33) where ξ ∈ (a, b) and

αi = Z n+1

−1 n

Y

j=0

j6=i

t − j

i − j dt, i = 0, 1, . . . , n. (34)

Consequently, the degree of accuracy is n + 1 when n is an even integer, and n when n is an odd integer.

T.M. Huang (Nat. Taiwan Normal Univ.) Numerical Diff. & integ. January 1, 2008 31 / 31

(46)

師大

The simplest open Newton-Cotes formula is choosing n = 0 and only using the midpoint x0 = a+b2 . Then the coefficient and the error term can be computed easily as

α0= Z −1

1

dt = 2, and h3f00(ξ) 2!

Z 1

−1

t2dt = 1

3f00(ξ)h3.

These gives the so-called Midpoint rule or Rectangular rule.

Midpoint Rule:

Z b

a

f (x) dx = 2hf (x0) +1

3f00(ξ)h3 = (b − a)f (a + b 2 ) +1

3f00(ξ)h3, (35)

for some ξ ∈ (a, b).

Analogous to the closed Newton-Cotes formulas, we list some of the commonly used open Newton-Cotes formulas in the following table.

(47)

師大

Name n s σi Error

Midpoint rule 0 1 2 13f(2)(ξ)h3 1 2 3, 3 34f(2)(ξ)h3 2 3 8, −4, 8 1445f(4)(ξ)h5 3 24 55, 5, 5, 55 14495f(4)(ξ)h5

It is obvious that the Newton-Cotes formulas are generally not suitable for numerical integration over large interval. Higher degree formulas would be required, and the coefficients in these formulas are difficult to obtain. Also the Newton-Cotes formulas which are based on polynomial interpolation would be inaccurate over a large interval because of the oscillatory nature of high-degree polynomials. Now we discuss a piecewise approach, called composite rule, to numerical integration over large interval that uses the low-order Newton-Cotes formulas.

A composite rule is one obtained by applying an integration formula for a single interval to each subinterval of a partitioned interval. To illustrate the procedure, we choose an even integer n and partition the interval [a, b]

into n subintervals by nodes x0 < x1< · · · < xn= b, and apply Simpson’s

(48)

師大

rule on each consecutive pair of subintervals. With

h = b − a

n and xj = a + jh, j = 0, 1, . . . , n,

we have on each interval [x2j−2, x2j],

Z x2j

x2j−2

f (x) dx = h

3 [f (x2j−2) + 4f (x2j−1) + f (x2j)] − h5

90f(4)j),

for some ξ ∈ (x , x ), provided that f ∈ C4[a, b]. The composite rule

(49)

師大

is obtained by summing up over the entire interval, that is, Z b

a

f (x) dx =

n/2

X

j=1

Z x2j

x2j−2

f (x) dx

=

n/2

X

j=1

 h

3(f (x2j−2) + 4f (x2j−1) + f (x2j)) − h5

90f(4)j)



= h

3[f (x0) + 4f (x1) + f (x2) + f (x2) + 4f (x3) + f (x4) + f (x4) + 4f (x5) + · · · + f (xn−2) + 4f (xn−1) + f (xn)] − h5

90

n/2

X

j=1

f(4)j)

= h

3[f (x0) + 4f (x1) + 2f (x2) + 4f (x3) + 2f (x4) + 4f (x5) + · · · + 2f (xn−2) + 4f (xn−1) + f (xn)] − h5

90

n/2

X

j=1

f(4)j)

= h

3

f (x0) + 4

n/2

X

j=1

f (x2j−1) + 2

(n/2)−1

X

j=1

f (x2j) + f (xn)

− h5 90

n/2

X

j=1

f(4)j).

T.M. Huang (Nat. Taiwan Normal Univ.) Numerical Diff. & integ. January 1, 2008 31 / 31

(50)

師大

To estimate the error associated with approximation, since f ∈ C4[a, b], we have, by the Extreme Value Theorem,

min

x∈[a,b]f(4)(x) ≤ f(4)j) ≤ max

x∈[a,b]f(4)(x), for each ξj ∈ (x2j−2, x2j). Hence

n 2 min

x∈[a,b]f(4)(x) ≤

n/2

X

j=1

f(4)j) ≤ n 2 max

x∈[a,b]f(4)(x), and

x∈[a,b]min f(4)(x) ≤ 2 n

n/2

X

j=1

f(4)j) ≤ max

x∈[a,b]f(4)(x).

By the Intermediate Value Theorem, there exists µ ∈ (a, b) such that

f(4)(µ) = 2 n

n/2

Xf(4)j).

(51)

師大

Thus, by replacing n = (b − a)/h,

n/2

X

j=1

f(4)j) = n

2f(4)(µ) = b − a

2h f(4)(µ).

Consequently, the composite Simpson’s rule is derived.

Composite Simpson’s Rule:

Z b a

f (x) dx = h 3

f (a) + 4

n/2

X

j=1

f (x2j−1) + 2

(n/2)−1

X

j=1

f (x2j) + f (b)

−b − a

180 f(4)(µ)h4, (36)

where n is an even integer, h = (b − a)/n, xj = a + jh, for j = 0, 1, . . . , n, and some µ ∈ (a, b).

The composite Midpoint rule can be derived in a similar way, except the midpoint rule is applied on each subinterval [x2j−1, x2j] instead. That is,

Z x2j

x2j−2

f (x) dx = 2hf (x2j−1) +h3

3 f00j), j = 1, 2, . . . ,n 2.

(52)

師大

Note that n must again be even. Consequently, Z b

a

f (x) dx = 2h

n/2

X

j=1

f (x2j−1) +h3 3

n/2

X

j=1

f00j).

The error term can be written as

n/2

X

j=1

f00j) = n

2f00(µ) = b − a 2h f00(µ),

for some µ ∈ (a, b). Therefore, the composite Midpoint rule has the following formulation.

Composite Midpoint Rule:

Z b a

f (x) dx = 2h

n/2

X

j=1

f (x2j−1) −b − a

6 f00(µ)h2, (37) where n is an even integer, h = (b − a)/n, xj = a + jh, for

j = 0, 1, . . . , n, and some µ ∈ (a, b).

(53)

師大

To derive the composite Trapezoidal rule, we partition the interval [a, b] by n equally spaced nodes a = x0 < x1 < · · · < xn= b, where n can be either odd or even. We then apply the trapezoidal rule on each subinterval

(54)

師大

[xj−1, xj] and sum them up to obtain Z b

a

f (x) dx =

n

X

j=1

Z xj

xj−1

f (x) dx

=

n

X

j=1

 h

2(f (xj−1) + f (xj)) −h3 12f00j)



= h

2[f (x0) + f (x1) + f (x1) + f (x2) + · · · + f (xn−1) + f (xn)] − h3 12

n

X

j=1

f00j)

= h

2[f (x0) + 2f (x1) + 2f (x2) + · · · + 2f (xn−1) + f (xn)] − h3 12

n

X

j=1

f00j)

= h

2

f (a) +

n−1

X

j=1

f (xj) + f (b)

−h3 12

n

X

j=1

f00j)

= h

2

f (a) +

n−1

Xf (xj) + f (b)

−b − a

12 f00(µ)h2,

(55)

師大

where each ξj ∈ (xj−1, xj) and µ ∈ (a, b).

Composite Trapezoidal Rule Z b

a

f (x) dx = h 2

f (a) +

n−1

X

j=1

f (xj) + f (b)

− b − a

12 f00(µ)h2, (38) where n is an integer, h = (b − a)/n, xj = a + jh, for j = 0, 1, . . . , n, and some µ ∈ (a, b).

參考文獻

相關文件

These humanistic qualities of Buddhism are expressed in the following three dichotomous principles: “the good and the most good,” “the expedient and the transcendental,” and

We will present some applications of the the- ory, including the derivations of the wallcrossing formulas, higher rank Donaldson-Thomas invariants on local curves, and the

volume suppressed mass: (TeV) 2 /M P ∼ 10 −4 eV → mm range can be experimentally tested for any number of extra dimensions - Light U(1) gauge bosons: no derivative couplings. =&gt;

The existence of cosmic-ray particles having such a great energy is of importance to astrophys- ics because such particles (believed to be atomic nuclei) have very great

• Formation of massive primordial stars as origin of objects in the early universe. • Supernova explosions might be visible to the most

where L is lower triangular and U is upper triangular, then the operation counts can be reduced to O(2n 2 )!.. The results are shown in the following table... 113) in

The superlinear convergence of Broyden’s method for Example 1 is demonstrated in the following table, and the computed solutions are less accurate than those computed by

Numerical experiments indicate that our alternative reconstruction formulas perform significantly better than the standard scaling function series (1.1) for smooth f and are no