Integration COS 323. Numerical Integration Problems Basic 1D numerical integration:Basic 1D...

17
Integration Integration COS 323 COS 323
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    233
  • download

    4

Transcript of Integration COS 323. Numerical Integration Problems Basic 1D numerical integration:Basic 1D...

IntegrationIntegration

COS 323COS 323

Numerical Integration ProblemsNumerical Integration Problems

• Basic 1D numerical integration:Basic 1D numerical integration:– GivenGiven ability to evaluate ability to evaluate ff ((xx)) for any for any xx, , findfind

– Goal:Goal: best accuracy with fewest samples best accuracy with fewest samples

• Other problems (future lectures):Other problems (future lectures):– Improper integration Improper integration

– Multi-dimensional integrationMulti-dimensional integration

– Ordinary differential equationsOrdinary differential equations

– Partial differential equationsPartial differential equations

b

a

dxxf )(b

a

dxxf )(

Trapezoidal RuleTrapezoidal Rule

• Approximate function by trapezoidApproximate function by trapezoid

aa bb

f(a)f(a)

f(b)f(b)

Trapezoidal RuleTrapezoidal Rule

aa bb

f(a)f(a)

f(b)f(b)

2

)()()()(

bfafabdxxf

b

a

2

)()()()(

bfafabdxxf

b

a

Extended Trapezoidal RuleExtended Trapezoidal Rule

aa bb

f(a)f(a)

f(b)f(b)

2

)()()()(

bfafabdxxf

b

a

2

)()()()(

bfafabdxxf

b

a

)()()()()( 21

1121 bfxfxfafhdxxf n

b

a

)()()()()( 21

1121 bfxfxfafhdxxf n

b

a

Divide into segments of width Divide into segments of width hh::

aa bb

Trapezoidal Rule Error AnalysisTrapezoidal Rule Error Analysis

• How accurate is this approximation?How accurate is this approximation?

• Start with Taylor series for Start with Taylor series for ff ((xx)) around around aa

)()()()()()( 221 afaxafaxafxf )()()()()()( 221 afaxafaxafxf

E

)()(2

)()( bfaf

abdxxf

b

a

E

)()(2

)()( bfaf

abdxxf

b

a

Trapezoidal Rule Error AnalysisTrapezoidal Rule Error Analysis

• Expand LHS:Expand LHS:

• Expand RHSExpand RHS

)()()()()()()( 3612

21 afabafabafabdxxf

b

a

)()()()()()()( 3612

21 afabafabafabdxxf

b

a

E

E

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

)()()()(2

)(

3412

21

21

21

afabafabafab

afabbfafab

E

E

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

)()()()(2

)(

3412

21

21

21

afabafabafab

afabbfafab

Trapezoidal Rule Error AnalysisTrapezoidal Rule Error Analysis

• So,So,

• In general, error for a In general, error for a singlesingle segment segment proportional to proportional to hh33

• Error for subdividing entire aError for subdividing entire ab interval b interval proportional to proportional to hh22

– ““Cubic local accuracy, quadratic global Cubic local accuracy, quadratic global accuracy”accuracy”

)()( 3121 afabE )()( 3

121 afabE

Determining Step SizeDetermining Step Size

• Change in integral when reducing step Change in integral when reducing step sizesizeis a reasonable guess for accuracyis a reasonable guess for accuracy

• For trapezoidal rule, easy to go from h For trapezoidal rule, easy to go from h h/2h/2without wasting previous sampleswithout wasting previous samples

aa bb

• Approximate integral byApproximate integral byparabola throughparabola throughthree pointsthree points

• Better accuracy for same # of Better accuracy for same # of evaluationsevaluations

Simpson’s RuleSimpson’s Rule

aa bb

f(a)f(a)

f(b)f(b)

)()()(4)(3

)( 5hObfhafafh

dxxfb

a

)()()(4)(3

)( 5hObfhafafh

dxxfb

a

Richardson ExtrapolationRichardson Extrapolation

• Better way of getting higher accuracy for aBetter way of getting higher accuracy for agiven # of samplesgiven # of samples

• Suppose we’ve evaluated integral for step Suppose we’ve evaluated integral for step sizesizeh and step size h/2:h and step size h/2:

• ThenThen

4

2

2

22/

42

hhh

h

FF

hhFF

4

2

2

22/

42

hhh

h

FF

hhFF

)( 431

2/34 hOFFF hh )( 4

31

2/34 hOFFF hh

Richardson ExtrapolationRichardson Extrapolation

• This treats the approximation as a This treats the approximation as a function of h and “extrapolates” the function of h and “extrapolates” the result to h=0result to h=0

• Can repeat:Can repeat:

)()()()( 8642

8/

4/

2/

hOhOhOhO

F

F

F

F

h

h

h

h

)()()()( 8642

8/

4/

2/

hOhOhOhO

F

F

F

F

h

h

h

h ––1/31/3

4/34/3 ––1/151/15

16/1516/15 ––1/631/63

64/6364/63

Open MethodsOpen Methods

• Trapezoidal rule won’t work if function Trapezoidal rule won’t work if function undefined at one of the points where undefined at one of the points where evaluatingevaluating– Most often: function infinite at one endpointMost often: function infinite at one endpoint

• Open methods only evaluate function Open methods only evaluate function on the on the openopen interval (i.e., not at interval (i.e., not at endpoints)endpoints)

1

02x

dx1

02x

dx

Midpoint RuleMidpoint Rule

• Approximate function by rectangle Approximate function by rectangle evaluated at midpointevaluated at midpoint

aa bb

)( 2baf )( 2baf

Extended Midpoint RuleExtended Midpoint Rule

)()()( 2ba

b

a

fabdxxf )()()( 2ba

b

a

fabdxxf

)()()()( 223

2hhh

b

a

bfafafhdxxf )()()()( 223

2hhh

b

a

bfafafhdxxf

Divide into segments of width Divide into segments of width hh::

aa bb

aa bb

Midpoint Rule Error AnalysisMidpoint Rule Error Analysis

• Following similar analysis to trapezoidal Following similar analysis to trapezoidal rule,rule,find that local accuracy is cubic,find that local accuracy is cubic,quadratic global accuracyquadratic global accuracy

• Formula suitable for adaptive method,Formula suitable for adaptive method,Richardson extrapolation,Richardson extrapolation,but can’t halve intervals withoutbut can’t halve intervals withoutwasting sampleswasting samples

DiscontinuitiesDiscontinuities

• All the above error analyses assumed nice All the above error analyses assumed nice (continuous, differentiable) functions(continuous, differentiable) functions

• In the presence of a discontinuity, all methodsIn the presence of a discontinuity, all methodsrevert to accuracy proportional to hrevert to accuracy proportional to h

• Locally-adaptive methods: do not subdivideLocally-adaptive methods: do not subdivideall intervals equally, focus on those with large all intervals equally, focus on those with large errorerror(estimated from change with a single (estimated from change with a single subdivision)subdivision)