chapter 17 numerical integration formulas. graphical representation of integral integral = area...

Post on 21-Dec-2015

252 Views

Category:

Documents

7 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 17Chapter 17

Numerical Numerical Integration FormulasIntegration Formulas

max 0 1

1

Integration

( ) ( )

( )

limM b

i i ax i

M

i ii

y f(x)

I f x x f x dx

A f x x I

Graphical Representation of IntegralGraphical Representation of Integral

Integral = area under the curve

Use of a grid to approximate an integral

Use of strips to Use of strips to approximate an integralapproximate an integral

Numerical IntegrationNumerical Integration

Net force against a

skyscraper

Cross-sectional area and volume flowrate

in a river

Survey of land area of an

irregular lot

Water exerting pressure on the upstream face of a dam: (a) side view showing force increasing linearly with

depth; (b) front view showing width of dam in meters.

Pressure Force on a DamPressure Force on a Dam

p = gh = h

IntegrationIntegration Weighted sum of functional values at discrete

points Newton-Cotes closed or open formulae -- evenly spaced points Approximate the function by Lagrange

interpolation polynomial Integration of a simple interpolation polynomial

Guassian Quadratures Richardson extrapolation and Romberg

integration

Basic Numerical IntegrationBasic Numerical Integration Weighted sum of function values

)()()(

)()(

nn1100

i

n

0ii

b

a

xfcxfcxfc

xfcdxxf

x0 x1 xnxn-1x

f(x)

0

2

4

6

8

10

12

3 5 7 9 11 13 15

Numerical IntegrationNumerical Integration• Idea is to do integral in small parts, like the way

you first learned integration - a summation

• Numerical methods just try to make it faster and more accurate

Newton-Cotes formulas

- based on idea

dxxfdxxfIb

a n

b

a )()(

Approximate f(x) by a polynomial

nn

1n1n10n xaxaxaaxf

)(

Numerical integrationNumerical integration

fn (x) can be linear fn (x) can be quadratic

fn (x) can also be cubic or other higher-order polynomials

Polynomial can be piecewise over the data

Numerical IntegrationNumerical Integration

Newton-Cotes Closed Formulae -- Use both end points

Trapezoidal Rule : Linear Simpson’s 1/3-Rule : Quadratic Simpson’s 3/8-Rule : Cubic Boole’s Rule : Fourth-order* Higher-order methods*

Newton-Cotes Open Formulae -- Use only interior points

midpoint rule Higher-order methods

Closed and Open FormulaeClosed and Open Formulae

(a) End points are known (b) Extrapolation

Trapezoidal RuleTrapezoidal Rule• Straight-line approximation

)()(

)()()()(

10

1100i

1

0ii

b

a

xfxf2

h

xfcxfcxfcdxxf

x0 x1x

f(x)

L(x)

Trapezoidal RuleTrapezoidal Rule• Lagrange interpolation

)()()()()(

)()()(

)()()(

)()()()()(

;,,,

)()()(

bfaf2

h

2hbf

2haf

dhbfd1haf

dLhdxxLdxxf

bfaf1L1 bx

0 ax

abh h

dxd

ab

ax xb xa let

xfxx

xxxf

xx

xxxL

1

0

21

0

2

1

0

1

0

1

0

b

a

b

a

10

101

00

10

1

Example:Trapezoidal RuleExample:Trapezoidal Rule• Evaluate the integral• Exact solution

• Trapezoidal Rule

92647752161x2e4

1

e4

1e

2

xdxxe

1

0

x2

4

0

x2x24

0

x2

.)(

dxxe4

0

x2

%..

..

.)()()(

123579265216

66238479265216

6623847e4024f0f2

04dxxeI 84

0

x2

Better Numerical IntegrationBetter Numerical Integration

Composite integration Multiple applications of Newton-Cotes

formulae Composite Trapezoidal Rule Composite Simpson’s Rule

Richardson Extrapolation Romberg integration

Apply trapezoidal rule to multiple Apply trapezoidal rule to multiple segments over integration limitssegments over integration limits

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Two segments

0

1

2

3

4

5

6

7

3 5 7 9 11 13 15

0

1

2

3

4

5

6

7

3 5 7 9 11 13 150

1

2

3

4

5

6

7

3 5 7 9 11 13 15

Four segments Many segments

Three segments

Multiple Applications of Multiple Applications of Trapezoidal RuleTrapezoidal Rule

Composite Trapezoidal RuleComposite Trapezoidal Rule

)()()()()(

)()()()()()(

)()()()(

n1ni10

n1n2110

x

x

x

x

x

x

b

a

xfxf2x2fxf2xf2

h

xfxf2

hxfxf

2

hxfxf

2

h

dxxfdxxfdxxfdxxfn

1n

2

1

1

0

x0 x1x

f(x)

x2h h x3h h x4

n

abh

Trapezoidal RuleTrapezoidal Rule Truncation error (single application)

Exact if the function is linear ( f = 0) Use multiple applications to reduce the

truncation error

3t abf

12

1E ))((

n

1ii2

3

n

1ii3

3

a

fn

1f ;f

n12

ab

fn12

abE

)()(

)()(

Approximate

error

Composite Trapezoidal RuleComposite Trapezoidal Rule

function f = example1(x)% a = 0, b = pif=x.^2.*sin(2*x);

dxx2sinx0

2 )(

» a=0; b=pi; dx=(b-a)/100;» x=a:dx:b; y=example1(x);» I=trap('example1',a,b,1)I = -3.7970e-015» I=trap('example1',a,b,2)I = -1.4239e-015» I=trap('example1',a,b,4)I = -3.8758» I=trap('example1',a,b,8)I = -4.6785» I=trap('example1',a,b,16)I = -4.8712» I=trap('example1',a,b,32)I = -4.9189

Composite Trapezoidal RuleComposite Trapezoidal Rule» I=trap('example1',a,b,64)I = -4.9308» I=trap('example1',a,b,128)I = -4.9338» I=trap('example1',a,b,256)I = -4.9346» I=trap('example1',a,b,512)I = -4.9347» I=trap('example1',a,b,1024)I = -4.9348» Q=quad8('example1',a,b)Q = -4.9348 MATLAB

function

n = 2

I = -1.4239 e-15

Exact = -4. 9348

dxx2sinx0

2 )(

n = 4

I = -3.8758

Exact = -4. 9348

dxx2sinx0

2 )(

n = 8

I = -4.6785

Exact = -4. 9348

dxx2sinx0

2 )(

n = 16

I = -4.8712

Exact = -4. 9348

dxx2sinx0

2 )(

Composite Trapezoidal RuleComposite Trapezoidal Rule• Evaluate the integral dxxeI

4

0

x2

%..)().().(

).().()(.,

%..)().(

)().()().(

)().()(.,

%..)()(

)()()(,

%..)()()(,

%..)()(,

662 9553554f753f253f2

50f2250f20f2

hI250h16n

5010 7657644f53f2

3f252f22f251f2

1f250f20f2

hI50h8n

7139 7972884f3f2

2f21f20f2

hI1h4n

75132 23121424f2f20f2

hI2h2n

12357 66238474f0f2

hI4h1n

Composite Trapezoidal RuleComposite Trapezoidal Rule» x=0:0.04:4; y=example2(x);» x1=0:4:4; y1=example2(x1);» x2=0:2:4; y2=example2(x2);» x3=0:1:4; y3=example2(x3);» x4=0:0.5:4; y4=example2(x4);» H=plot(x,y,x1,y1,'g-*',x2,y2,'r-s',x3,y3,'c-o',x4,y4,'m-d');» set(H,'LineWidth',3,'MarkerSize',12);» xlabel('x'); ylabel('y'); title('f(x) = x exp(2x)');

» I=trap('example2',0,4,1)I = 2.3848e+004» I=trap('example2',0,4,2)I = 1.2142e+004» I=trap('example2',0,4,4)I = 7.2888e+003» I=trap('example2',0,4,8)I = 5.7648e+003» I=trap('example2',0,4,16)I = 5.3559e+003

Composite Trapezoidal RuleComposite Trapezoidal Rule

dxxeI4

0

x2

Simpson’s 1/3-RuleSimpson’s 1/3-Rule• Approximate the function by a parabola

)()()(

)()()()()(

210

221100i

2

0ii

b

a

xfxf4xf3

h

xfcxfcxfcxfcdxxf

x0 x1x

f(x)

x2h h

L(x)

Simpson’s 1/3-RuleSimpson’s 1/3-Rule

1 xx

0 xx

1 xx

h

dxd

h

xx

2

abh

2

ba x bx ax let

xfxxxx

xxxx

xfxxxx

xxxx xf

xxxx

xxxxxL

2

1

0

1

120

21202

10

12101

200

2010

21

,,

,,

)())((

))((

)())((

))(()(

))((

))(()(

)()(

)()()()(

)( 212

0 xf2

1xf1xf

2

1L

Simpson’s 1/3-RuleSimpson’s 1/3-Rule)(

)()()()(

)()( 21

20 xf

2

1xf1xf

2

1L

1

1

23

2

1

1

3

1

1

1

23

0

1

12

1

0

21

1

10

1

1

b

a

2

ξ

3

ξ

2

hxf

3

ξξhxf

2

ξ

3

ξ

2

hxf

dξ1ξξ2

hxfdξξ1(hxf

dξ1ξξ2

hxfdξLhdxxf

)()(

)()()()(

)()())(

)()()()(

)()()()( 210

b

axfxf4xf

3

hdxxf

Composite Simpson’s RuleComposite Simpson’s Rule

x0 x2x

f(x)

x4h h xn-2h xn

n

abh

…...

Piecewise Quadratic approximations

hx3x1 xn-1

Composite Simpson’s 1/3 RuleComposite Simpson’s 1/3 Rule

Applicable only if the number of segments is even

Composite Simpson’s 1/3 RuleComposite Simpson’s 1/3 Rule Applicable only if the number of segments is even

Substitute Simpson’s 1/3 rule for each integral

For uniform spacing (equal segments)

n

2n

4

2

2

0

x

x

x

x

x

xdxxfdxxfdxxfI )()()(

6

xfxf4xfh2

6

xfxf4xfh2

6

xfxf4xfh2I

n1n2n

432210

)()()(

)()()()()()(

1n

531i

2n

642jnji0 xfxf2xf4xf

n3

abI

,, ,,

)()()()()(

Simpson’s 1/3 RuleSimpson’s 1/3 Rule Truncation error (single application)

Exact up to cubic polynomial ( f (4)= 0) Approximate error for (n/2) multiple

applications

2

abh ;f

2880

abfh

90

1E 4

545

t

)(

)()( )()(

5(4)

4

( )

180a

b aE f

n

Composite Simpson’s 1/3 RuleComposite Simpson’s 1/3 RuleEvaluate the integral

• n = 2, h = 2

• n = 4, h = 1

dxxeI4

0

x2

%..

)()()(

)()()()()(

708 9755670

e4e34e22e403

1

4f3f42f21f40f3

hI

8642

%..)(

)()()(

9657 4118240e4e2403

2

4f2f40f3

hI

84

Simpson’s 3/8-RuleSimpson’s 3/8-Rule Approximate by a cubic polynomial

)()()()(

)()()()()()(

3210

33221100i

3

0ii

b

a

xfxf3xf3xf8

h3

xfcxfcxfcxfcxfcdxxf

x0 x1x

f(x)

x2h h

L(x)

x3h

Simpson’s 3/8-RuleSimpson’s 3/8-Rule

)())()((

))()(()(

))()((

))()((

)())()((

))()(()(

))()((

))()(()(

3231303

2102

321202

310

1312101

3200

302010

321

xfxxxxxx

xxxxxxxf

xxxxxx

xxxxxx

xfxxxxxx

xxxxxxxf

xxxxxx

xxxxxxxL

)()()()( 3210

b

a

b

a

xfxf3xf3xf8

h33

abh ;L(x)dxf(x)dx

Truncation error

3

abh ;f

6480

abfh

80

3E 4

545

t

)(

)()( )()(

Example: Simpson’s RulesExample: Simpson’s Rules Evaluate the integral Simpson’s 1/3-Rule

Simpson’s 3/8-Rule

dxxe4

0

x2

%..

..

.)(

)()()(

96579265216

41182409265216

4118240e4e2403

2

4f2f40f3

hdxxeI

84

4

0

x2

%71.30926.5216

209.6819926.5216

209.6819832.11923)33933.552(3)18922.19(308

)4/3(3

)4(f)3

8(f3)

3

4(f3)0(f

8

h3dxxeI

4

0

x2

function I = Simp(f, a, b, n)% integral of f using composite Simpson rule% n must be evenh = (b - a)/n;S = feval(f,a);for i = 1 : 2 : n-1 x(i) = a + h*i; S = S + 4*feval(f, x(i));endfor i = 2 : 2 : n-2 x(i) = a + h*i; S = S + 2*feval(f, x(i));endS = S + feval(f, b); I = h*S/3;

Composite Simpson’s 1/3 RuleComposite Simpson’s 1/3 Rule

Simpson’s 1/3 RuleSimpson’s 1/3 Rule

Composite Simpson’s 1/3 RuleComposite Simpson’s 1/3 Rule

» x=0:0.04:4; y=example(x);» x1=0:2:4; y1=example(x1);» c=Lagrange_coef(x1,y1); p1=Lagrange_eval(x,x1,c);» H=plot(x,y,x1,y1,'r*',x,p1,'r');» xlabel('x'); ylabel('y'); title('f(x) = x*exp(2x)');» set(H,'LineWidth',3,'MarkerSize',12);» x2=0:1:4; y2=example(x2);» c=Lagrange_coef(x2,y2); p2=Lagrange_eval(x,x2,c);» H=plot(x,y,x2,y2,'r*',x,p2,'r');» xlabel('x'); ylabel('y'); title('f(x) = x*exp(2x)');» set(H,'LineWidth',3,'MarkerSize',12);» » I=Simp('example',0,4,2)I = 8.2404e+003» I=Simp('example',0,4,4)I = 5.6710e+003» I=Simp('example',0,4,8)I = 5.2568e+003» I=Simp('example',0,4,16)I = 5.2197e+003» Q=Quad8('example',0,4)Q = 5.2169e+003

n = 2

n = 4

n = 8

n = 16

MATLAB fun

Multiple applications of Simpson’s rule Multiple applications of Simpson’s rule with odd number of intervalswith odd number of intervals

Hybrid Simpson’s 1/3 & 3/8 rules

Newton-Cotes Closed Newton-Cotes Closed Integration FormulaeIntegration Formulae

)()()()()()()(

)(

)()()()()()(

)(

)()()()()(

)(

)()()()(

)('

)()()(

)(

)(

)(

)(

)(

67543210

6743210

453210

45210

310

fh12096

275

288

xf19xf75xf50xf50xf75xf19ab5

fh945

8

90

xf7xf32xf12xf32xf7abrule sBoole'4

fh80

3

8

xfxf3xf3xfabrule 3/8sSimpson'3

fh90

1

6

xfxf4xfabrule 1/3 sSimpson2

fh12

1

2

xfxfabrule lTrapezoida1

Error TruncationFormulaNamen

n

abh

Composite Trapezoidal Rule with Composite Trapezoidal Rule with Unequal SegmentsUnequal Segments

Evaluate the integral h1 = 2, h2 = 1, h3 = 0.5, h4 = 0.5

dxxeI4

0

x2

%...

.

)().().()(

)()()()(

)()()()(.

.

4514 585971 e4e53 2

0.5

e533e 2

0.5e3e2

2

1e20

2

2

4f53f2

h53f3f

2

h

3f2f2

h2f0f

2

h

dxxfdxxfdxxfdxxfI

87

76644

43

21

4

53

53

3

3

2

2

0

Trapezoidal Rule for Unequally Spaced DataTrapezoidal Rule for Unequally Spaced Data

MATLAB Function: MATLAB Function: trapztrapz

» x=[0 1 1.5 2.0 2.5 3.0 3.3 3.6 3.8 3.9 4.0]

x =

Columns 1 through 7

0 1.0000 1.5000 2.0000 2.5000 3.0000 3.3000

Columns 8 through 11

3.6000 3.8000 3.9000 4.0000

» y=x.*exp(2.*x)

y =

1.0e+004 *

Columns 1 through 7

0 0.0007 0.0030 0.0109 0.0371 0.1210 0.2426

Columns 8 through 11

0.4822 0.7593 0.9518 1.1924

» integr = trapz(x,y)

integr =

5.3651e+003

Z = trapz(x,y)

Integral of Unevenly-Spaced DataIntegral of Unevenly-Spaced Data

Trapezoidal rule

Could also be evaluated with Simpson’s rule for higher accuracy

Composite Simpson’s Rule with Composite Simpson’s Rule with Unequal SegmentsUnequal Segments

• Evaluate the integral

• h1 = 1.5, h2 = 0.5

dxxeI4

0

x2

%..

).(.

).(.

)().()(

)().()(

)()(

763 235413

e4e534e33

50e3e5140

3

51

4f53f43f3

h

3f51f40f3

h

dxxfdxxfI

87663

2

1

4

3

3

0

Newton-Cotes Open FormulaNewton-Cotes Open FormulaMidpoint Rule Midpoint Rule ((One-pointOne-point))

)()(

)()(

)()()(

f24

ab

2

bafab

xfabdxxf

3

m

b

a

a b x

f(x)

xm

Two-point Newton-Cotes Open FormulaTwo-point Newton-Cotes Open Formula

Approximate by a straight line

)()(

)()()( f108

abxfxf

2

abdxxf

3

21

b

a

x0 x1x

f(x)

x2h h x3h

Three-point Newton-Cotes Open FormulaThree-point Newton-Cotes Open Formula

Approximate by a parabola

)()(

)()()()(

f23040

ab7

xf2xfxf23

abdxxf

5

321

b

a

x0 x1x

f(x)

x2h h x3h h x4

Newton-Cotes Open Newton-Cotes Open Integration FormulaeIntegration Formulae

)()()()()()(

)(

)()()()()(

)(

)()()()(

)(

)()()(

)(

)()()(

)(

)(

)(

6754321

454321

45321

321

31

fh140

41

20

xf11xf14xf26xf14xf11ab6

fh144

95

24

xf11xfxfxf11ab5

fh45

14

3

xf2xfxf2ab4

fh4

3

2

xfxfab3

fh3

1xfab2

Error TruncationFormulan

n

abh

Area under the function surface

Double IntegralDouble Integral

dydxyxfdxdyyxfdydxyxfd

c

b

a

b

a

d

c

d

c

b

a

),(),(),(

T(x, y) = 2xy + 2x – x2 – 2y2 + 40

Two-segment trapezoidal rule

Exact if using single-segment Simpson’s 1/3 rule (because the function is quadratic in x and y)

Double IntegralDouble Integral

top related