17
Chap. 18: Numerical Integration of Functions

Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

  • Upload
    vothuy

  • View
    226

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

Chap. 18: Numerical Integration of Functions

Page 2: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

2

Richardson Extrapolation• Richard extrapolation methods use two estimates

of an integral to compute a third, more accurate approximation.

• If two O(h2) estimates I(h1) and I(h2) are calculated for an integral using step sizes of h1 and h2, respectively, an improved O(h4) estimate may be formed using:

• For the special case where the interval is halved (h2=h1/2), this becomes:

I 43

I(h2 ) 13

I (h1)

I I(h2 ) 1(h1 /h2 )2 1

I(h2 ) I (h1)

Page 3: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

3

Richardson Extrapolation Derivation

II(h)E(h),where I(h) is the integral. E(h) is the error.Then I(h1)E(h1)I(h2)E(h2)

Since E ba12

h 2f̄

E(h1)E(h2)

h 2

1

h 22

I(h1)E(h2)h 2

1

h 22

I(h2)E(h2)

II(h2)1

h 21 /h 2

21I(h2)I(h1)

II(h)E(h),where I(h) is the integral. E(h) is the error.Then I(h1)E(h1)I(h2)E(h2)

Since E ba12

h 2f̄

E(h1)E(h2)

h 2

1

h 22

I(h1)E(h2)h 2

1

h 22

I(h2)E(h2)

II(h2)1

h 21 /h 2

21I(h2)I(h1)

Page 4: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

4

Example 18.1

• Integrate the following function from 0 to 0.8. Exact value: 1.640533

f(x)0.225x200x 2675x 3900x 4400x 5

I43

(1.0688) 13

(0.1728)1.367467 (εt16.6%)

I43

(1.4848) 13

(1.0688)1.623467 (εt1%)

f(x)0.225x200x 2675x 3900x 4400x 5

I43

(1.0688) 13

(0.1728)1.367467 (εt16.6%)

I43

(1.4848) 13

(1.0688)1.623467 (εt1%)

Page 5: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

5

Richardson Extrapolation (cont)

• For the cases where there are two O(h4) estimates and the interval is halved (hm=hl/2), an improved O(h6) estimate may be formed using:

• For the cases where there are two O(h6) estimates and the interval is halved (hm=hl/2), an improved O(h8) estimate may be formed using:

I 1615

Im 1

15I l

I 6463

Im 163

I l

Page 6: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

6

Example 18.2

• Redo Example 18.1 with Higher order correction.

I1615

(1.623467) 115

(1.367467)1.640533 (εt0%)I1615

(1.623467) 115

(1.367467)1.640533 (εt0%)

Page 7: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

7

The Romberg Integration Algorithm

• Note that the weighting factors for the Richardson extrapolation add up to 1 and that as accuracy increases, the approximation using the smaller step size is given greater weight.

• In general,

where Ij+1,k-1 and Ij,k-1 are the more and less accurate integrals, respectively, and Ij,k is the new approximation. k is the level of integration and jis used to determine which approximation is more accurate.

I j,k 4 k1 I j1,k1 I j ,k1

4 k1 1

Page 8: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

8

Romberg Algorithm Iterations

• The chart below shows the process by which lower level integrations are combined to produce more accurate estimates:

Page 9: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

9

Gauss Quadrature

• Variable sampling position instead of fixed or equal spaced.

• To be determined:– Sampling points.– Weighting at each sampling

points.• Benefit: give better accuracy

than Simpson’s rules under the same number of sampling points.

Page 10: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

10

Gauss-Legendre Formulas

• Fix integral intervals from -1 to 1.• Integrals over other intervals require a

change in variables to set the limits from -1 to 1.

• The integral estimates are of the form:

where the ci and xi are to be determined to ensure exact solution up to (2n-1)th order polynomials over the interval from -1 to 1.

I c0 f x0 c1 f x1 cn1 f xn1

Page 11: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

11

Example: Two-Point Gauss-Legendre Formula

• Let• Goal: determine the unknowns

c0, c1, x0, x1.• Method: Use 4 conditions to

solve 4 unknowns, that is I gives the correct result of

Ic0f(x0)c1f(x1)Ic0f(x0)c1f(x1)

I1

1

f(x)dx

when f(x)1, f(x)x, f(x)x 2 and f(x)x 3

I1

1

f(x)dx

when f(x)1, f(x)x, f(x)x 2 and f(x)x 3

Page 12: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

12

Example: Two-Point Gauss-Legendre Formula (cont.)

c0c11

1

1dx2

c0x0c1x11

1

xdx0

c0x20c1x

21

1

1

x 2dx 23

c0x30c1x

31

1

1

x 3dx0

c0c11

1

1dx2

c0x0c1x11

1

xdx0

c0x20c1x

21

1

1

x 2dx 23

c0x30c1x

31

1

1

x 3dx0

c0c11, x013

, x113

c0c11, x013

, x113

Page 13: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

13

Change of Variables

• For an arbitrary integral interval [a, b], let

• To sum up:– Find the new sampling points by the change of variable

formula.– Compute the integral by timing the weighting

coeffiecnts.– Multiply the result by (b-a)/2.

x(ba)(ba)xd

2 dxba

2dxd

b

a

f(x)dxba2

1

1

f(ba)(ba)xd

2dxd

x(ba)(ba)xd

2 dxba

2dxd

b

a

f(x)dxba2

1

1

f(ba)(ba)xd

2dxd

Page 14: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

14

Comparison

• Simpson’s rule– Fixed equal spacing.– Can be used for experimental data.– Less efficient.

• Gauss Quadrature– Not equal spacing.– Can only be used to integrate a known function.– More efficient.

Page 15: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

15

Adaptive Quadrature

• Equal size segments: Methods such as Simpson’s 1/3 rule has a disadvantage in that it uses equally spaced points - if a function has regions of abrupt changes, small steps must be used over the entire domain to achieve a certain accuracy.

• Adaptive quadrature methods: automatically adjust the step size so that small steps are taken in regions of sharp variations and larger steps are taken where the function changes gradually.

Page 16: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

16

Example 18.5

• Integrate from 0 to 1.

• Exact: 29.85832539549

• Adap. Simpson10-4 tolerance: 77 evaluation.

• Not adaptive: 3551

f(x) 1(xq)20.01

1

(xr)20.04sf(x) 1

(xq)20.01

1(xr)20.04

s

0 0.2 0.4 0.6 0.8 10

10

20

30

40

50

60

70

80

90

100

x

yq=0.3, r=0.9, s=6

Page 17: Chap. 18: Numerical Integration of Functions - ntut.edu.tjuiching/NMChap18.pdf · Chap. 18: Numerical Integration of Functions. 2 ... The Romberg Integration Algorithm ... 12 Example:

18

Adaptive Quadrature in MATLAB

• quad: uses adaptive Simpson quadrature; possibly more efficient for low accuracies or nonsmoothfunctions

• quadl: uses Lobatto quadrature; possibly more efficient for high accuracies and smooth functions

• q = quad(fun, a, b, tol, trace, p1, p2, …)– fun : function to be integrates– a, b: integration bounds– tol: desired absolute tolerance (default: 10-6)– trace: flag to display details or not– p1, p2, …: extra parameters for fun– quadl has the same arguments