cise301 : numerical methods topic 7 numerical integration lecture 24-27

57
CISE301_Topic7 KFUPM 1 CISE301: Numerical Methods Topic 7 Numerical Integration Lecture 24-27 KFUPM Read Chapter 21, Section 1 Read Chapter 22, Sections 2-3

Upload: shika

Post on 23-Feb-2016

57 views

Category:

Documents


1 download

DESCRIPTION

CISE301 : Numerical Methods Topic 7 Numerical Integration Lecture 24-27. KFUPM Read Chapter 21, Section 1 Read Chapter 22, Sections 2-3. L ecture 24 Introduction to Numerical Integration. Definitions Upper and Lower Sums Trapezoid Method (Newton-Cotes Methods) Romberg Method - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 1

CISE301: Numerical Methods

Topic 7 Numerical Integration

Lecture 24-27

KFUPM

Read Chapter 21, Section 1Read Chapter 22, Sections 2-3

Page 2: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 2

Lecture 24Introduction to

Numerical Integration Definitions Upper and Lower Sums Trapezoid Method (Newton-Cotes Methods) Romberg Method Gauss Quadrature Examples

Page 3: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 3

IntegrationIndefinite Integrals

Indefinite Integrals of a function are functions that differ from each other by a constant.

cxdxx2

2

Definite Integrals

Definite Integrals are numbers.

21

2

1

0

1

0

2

xxdx

Page 4: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 4

Fundamental Theorem of Calculus

:forsolution form closedNo

:for tiveantideriva no is There

) f(x)(x) 'F (i.e., f of tiveantideriva is , intervalan on continuous is If

2

2

b

a

x

x

b

a

dxe

e

F(a)F(b)f(x)dx

F[a,b]f

Page 5: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 5

The Area Under the Curve

b

af(x)dxArea

One interpretation of the definite integral is:

Integral = area under the curve

a b

f(x)

Page 6: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 6

Upper and Lower Sums

a b

f(x)

3210 xxxx

ii

n

ii

ii

n

ii

iii

iii

n

xxMPfUsumUpper

xxmPfLsumLower

xxxxfMxxxxfm

Define

bxxxxaPPartition

1

1

0

1

1

0

1

1

210

),(

),(

:)(max:)(min

...

The interval is divided into subintervals.

Page 7: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 7

Upper and Lower Sums

a b

f(x)

3210 xxxx

2

2 integral theof Estimate

),(

),(

1

1

0

1

1

0

LUError

UL

xxMPfUsumUpper

xxmPfLsumLower

ii

n

ii

ii

n

ii

Page 8: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 8

Example

143

21

4103,2,1,0

41

1,169,

41,

161

169,

41,

161,0

)intervals equalfour (4

1,43,

42,

41,0 :

1

3210

3210

1

0

2

iforxx

MMMM

mmmm

n

PPartition

dxx

ii

Page 9: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 9

Example

143

21

410

81

6414

6430

21

3211

6414

6430

21integraltheofEstimate

64301

169

41

161

41),(

),(

6414

169

41

1610

41),(

),(

1

1

0

1

1

0

Error

PfU

xxMPfUsumUpper

PfL

xxmPfLsumLower

ii

n

ii

ii

n

ii

Page 10: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 10

Upper and Lower Sums• Estimates based on Upper and Lower

Sums are easy to obtain for monotonic functions (always increasing or always decreasing).

• For non-monotonic functions, finding maximum and minimum of the function can be difficult and other methods can be more attractive.

Page 11: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 11

Newton-Cotes Methods In Newton-Cote Methods, the function

is approximated by a polynomial of order n.

Computing the integral of a polynomial is easy.

1)(...

2)()()(

...)(

1122

10

10

nabaabaabadxxf

dxxaxaadxxf

nn

n

b

a

b

a

nn

b

a

Page 12: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 12

Newton-Cotes Methods Trapezoid Method (First Order Polynomials are used)

Simpson 1/3 Rule (Second Order Polynomials are used)

b

a

b

a

b

a

b

a

dxxaxaadxxf

dxxaadxxf

2210

10

)(

)(

Page 13: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 13

Lecture 25Trapezoid Method

Derivation-One Interval Multiple Application Rule Estimating the Error Recursive Trapezoid Method

Read 21.1

Page 14: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 14

Trapezoid Method

)()()()( axab

afbfaf

f(x)

ba 2

)()(

2)()(

)()()(

)()()()(

)(

2

afbfab

xab

afbf

xab

afbfaaf

dxaxab

afbfafI

dxxfI

b

a

b

a

b

a

b

a

Page 15: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 15

Trapezoid MethodDerivation-One Interval

2

)()(

)()(2

)()()()()(

2)()()()()(

)()()()()(

)()()()()(

22

2

afbfab

ababafbfab

abafbfaaf

xab

afbfxab

afbfaaf

dxxab

afbfab

afbfaafI

dxaxab

afbfafdxxfI

b

a

b

a

b

a

b

a

b

a

Page 16: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 16

Trapezoid Method

)(bf

f(x)

ba

)()(2

bfafabArea

)(af

Page 17: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 17

Trapezoid MethodMultiple Application Rule

a b

f(x)

3210 xxxx

s trapezoid theof

areas theof sum)(

... segments into dpartitione

is b][a, intervalThe

210

b

a

n

dxxf

bxxxxan

1212

2)()( xxxfxfArea

x

Page 18: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 18

Trapezoid MethodGeneral Formula and Special Case

)()(21)(

... equal)y necessaril(not segments into divided is interval theIf

11

1

0

210

iiii

n

i

b

a

n

xfxfxxdxxf

bxxxxan

1

10

1

)()()(21)(

allfor points) base spacedEqualiy ( CaseSpecial

n

iin

b

a

ii

xfxfxfhdxxf

ihxx

Page 19: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 19

ExampleGiven a tabulated values of the velocity of an object.

Obtain an estimate of the distance traveled in the interval [0,3].

Time (s) 0.0 1.0 2.0 3.0

Velocity (m/s) 0.0 10 12 14

Distance = integral of the velocity

3

0)(Distance dttV

Page 20: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 20

Example 1Time (s) 0.0 1.0 2.0 3.0

Velocity (m/s)

0.0 10 12 14

29)140(2112)(101 Distance

)()(21)(

1

0

1

1

1

n

n

ii

ii

xfxfxfhT

xxhMethodTrapezoid

3,2,1,0are points Baselssubinterva3 into

divided is interval The

Page 21: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 21

Estimating the Error For Trapezoid Method

?accuracy digit decimal 5 to

)sin( compute toneeded

are intervals spacedequally many How

0

dxx

Page 22: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 22

Error in estimating the integralTheorem

)(''max12

)(12

then)( eapproximat

toused is Method Trapezoid If :Theorem) (width intervals Equal

on continuous is)('' :Assumption

],[

2

''2

a

xfhabError

[a,b]wherefhabError

dxxf

h[a,b]xf

bax

b

Page 23: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 23

Example

52

52

],[

2

5

0

106

1021

121)(''

)sin()('');cos()(';0;

)(''max12

1021 error ,)sin(

h

hErrorxf

xxfxxfab

xfhabError

thatsohfinddxx

bax

Page 24: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 24

Example

)()(21)(),(

, allfor :

)()(21),(

)(:compute tomethod Trapezoid Use

0

1

1

1

11

1

0

3

1

n

n

ii

ii

iiii

n

i

xfxfxfhPfT

ixxhCaseSpecial

xfxfxxPfTTrapezoid

dxxf

x 1.0 1.5 2.0 2.5 3.0

f(x) 2.1 3.2 3.4 2.8 2.7

Page 25: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 25

Example

9.5

7.21.2218.24.32.35.0

)()(21)()( 0

1

1

3

1

n

n

ii xfxfxfhdxxf

x 1.0 1.5 2.0 2.5 3.0

f(x) 2.1 3.2 3.4 2.8 2.7

Page 26: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 26

Recursive Trapezoid Method

f(x)

haa

)()(2

)0,0(R

:interval oneon based Estimate

bfafababh

Page 27: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 27

Recursive Trapezoid Method

f(x)

hahaa 2

)()0,0(21)0,1(

)()(21)(

2)0,1(R

2

:intervals 2on based Estimate

hafhRR

bfafhafab

abh

Based on previous estimate Based on new point

Page 28: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 28

Recursive Trapezoid Method

f(x)

)3()()0,1(21)0,2(

)()(21

)3()2()(4

)0,2(R

4

hafhafhRR

bfaf

hafhafhafab

abh

hahaa 42 Based on previous estimate Based on new points

Page 29: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 29

Recursive Trapezoid MethodFormulas

n

k

abh

hkafhnRnR

bfafab

n

2

)12()0,1(21)0,(

)()(2

)0,0(R

)1(2

1

Page 30: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 30

Recursive Trapezoid Method

)1(

2

2

1

2

13

2

12

1

1

)12()0,1(21)0,(,

2

..................

)12()0,2(21)0,3(,

2

)12()0,1(21)0,2(,

2

)12()0,0(21)0,1(,

2

)()(2

)0,0(R,

n

kn

k

k

k

hkafhnRnRabh

hkafhRRabh

hkafhRRabh

hkafhRRabh

bfafababh

Page 31: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 31

Advantages of Recursive TrapezoidRecursive Trapezoid: Gives the same answer as the standard

Trapezoid method. Makes use of the available information to

reduce the computation time. Useful if the number of iterations is not

known in advance.

Page 32: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 32

Lecture 26Romberg Method

Motivation Derivation of Romberg Method Romberg Method Example When to stop?

Read 22.2

Page 33: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 33

Motivation for Romberg Method Trapezoid formula with an interval h gives an

error of the order O(h2).

We can combine two Trapezoid estimates with intervals 2h and h to get a better estimate.

Page 34: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 34

Romberg Method

First column is obtained using Trapezoid Method

dx f(x) ofion approximat theimprove tocombined are

4h,8h,... 2h, h, size of intervals with method Trapezoid using Estimatesb

a

R(0,0)R(1,0) R(1,1)R(2,0) R(2,1) R(2,2)R(3,0) R(3,1) R(3,2) R(3,3)

The other elements are obtained using the Romberg Method

Page 35: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 35

First Column Recursive Trapezoid Method

n

k

abh

hkafhnRnR

bfafab

n

2

)12()0,1(21)0,(

)()(2

)0,0(R

)1(2

1

Page 36: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 36

Derivation of Romberg Method

...)0,1()0,(31)0,()(

2*41

)2(...641

161

41)0,()(

R(n,0)by obtained is estimate accurate More

)1(...)0,1()(

2 method Trapezoid)()0,1()(

66

44

66

44

22

66

44

22

12

hbhbnRnRnRdxxf

giveseqeq

eqhahahanRdxxf

eqhahahanRdxxf

abhwithhOnRdxxf

b

a

b

a

b

a

n

b

a

Page 37: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 37

Romberg Method

1,1

)1,1()1,(14

1)1,(),(

)12()0,1(21)0,(

,2

)()(2

)0,0(R

)1(2

1

mnfor

mnRmnRmnRmnR

hkafhnRnR

abh

bfafab

m

k

n

n

R(0,0)R(1,0) R(1,1)R(2,0) R(2,1) R(2,2)R(3,0) R(3,1) R(3,2) R(3,3)

Page 38: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 38

Property of Romberg Method

)(),()(

Theorem

22 mb

a

hOmnRdxxf

R(0,0)R(1,0) R(1,1)R(2,0) R(2,1) R(2,2)R(3,0) R(3,1) R(3,2) R(3,3)

)()()()( 8642 hOhOhOhOError Level

Page 39: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 39

Example 1

31

21

83

31

83)0,0()0,1(

141)0,1()1,1(

1,1

)1,1()1,(14

1)1,(),(

83

41

21

21

21))(()0,0(

21)0,1(,

21

5.01021)()(

2)0,0(,1

Compute

1

1

02

RRRR

mnfor

mnRmnRmnRmnR

hafhRRh

bfafabRh

dxx

m

0.53/8 1/3

Page 40: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 40

Example 1 (cont.)

31

31

31

151

31)1,1()1,2(

141)1,2()2,2(

31

83

3211

31

3211)0,1()0,2(

141)0,1()1,2(

)1,1()1,(14

1)1,(),(

3211

169

161

41

83

21))3()(()0,1(

21)0,2(,

41

2

1

RRRR

RRRR

mnRmnRmnRmnR

hafhafhRRh

m

0.5

3/8 1/3

11/32 1/3 1/3

Page 41: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 41

When do we stop?

R(4,4)at STOP example,for steps, ofnumber given aAfter

or

)1,1()1,( mnRmnRifSTOP

Page 42: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 42

Lecture 27Gauss Quadrature

Motivation General integration formula

Read 22.3

Page 43: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 43

Motivation

nandihnih

cwhere

xfcdxxf

xfxfxfhdxxf

i

n

iii

b

a

n

ini

b

a

05.01,...,2,1

)()(

:as expressed becan It

)()(21)()(

:Method Trapezoid

0

1

10

Page 44: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 44

General Integration Formula

integral? theofion approximat good a givesformula e that thsoselect wedo How

:Problem::

)()(0

ii

ii

n

iii

b

a

xandc

NodesxWeightsc

xfcdxxf

Page 45: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 45

Lagrange Interpolation

b

a ii

n

iii

b

a

b

a i

n

ii

b

a n

b

a

n

n

b

a n

b

a

dxxcwherexfcdxxf

dxxfxdxxPdxxf

xxxxPwhere

dxxPdxxf

)()()(

)()()()(

,...,, :nodes at thef(x) esinterpolat that polynomial a is )(

)()(

0

0

10

Page 46: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 46

Question

What is the best way to choose the nodes and the weights?

Page 47: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 47

Theorem

1.2norder of spolynomial allfor exact be willformula The

)()()(

: then)( of zeros theare,...,,,Let

00)(

:such that 1n degree of polynomial nontrivial a be Let

0

210

dxxcwherexfcdxxf

xqxxxx

nkdxxqx

q

i

b

ai

n

iii

b

a

n

kb

a

Page 48: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 48

Weighted Gaussian QuadratureTheorem

12norder of polynomial a isnever exact whe be willformula The

)(,)()(

:)()()(

: then)( of zeros theare,...,,,Let

00)()(

:such that 1 degree of polynomial nontrivial a be Let

0

0

210

f(x)

xxxx

xdxxwxc

wherexfcdxxwxf

xqxxxx

nkdxxwxqx

nq

n

ijj ji

jii

b

ai

n

iii

b

a

n

kb

a

Page 49: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 49

Determining The Weights and Nodes

?5order of spolynomial allfor exact is formula that theso

weights theand nodes select the wedo How

)()()()( 221100

1

1

xfcxfcxfcdxxf

Page 50: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 50

Determining The Weights and NodesSolution

5,3,0solution possible One

0)(

0)(

0)(

:satisfymust )()(

3120

1

1

2

1

1

1

1

33

2210

aaaa

dxxxq

xdxxq

dxxq

xqxaxaxaaxqLet

Page 51: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 51

Determining The Weights and NodesSolution

3

0 1 2

1

0 1 21

( ) 3 5

3( ) are 0, 5

3 3The nodes are , 0, 5 5

To obtain the weights we use

3 3( ) 05 5

Let q x x x

roots of q x

x x x

f x dx c f c f c f

Page 52: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 52

Determining The Weights and NodesSolution

0 1 2

0 1 2

1

1

3 3The nodes are , 0, 5 5

5 8 5The weights are , , 9 9 9

The Gauss Quadrature (n 2)

5 3 8 5 3( ) 09 5 9 9 5

x x x

c c c

f x dx f f f

Page 53: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 53

Gaussian QuadratureSee more in Table 22.1 (page 646)

236926.0,478628.0,568889.0,478628.0,236926.0906179.0,538469.0,00000.0,538469.0,906179.04

34785.0,65214.0,65214.0,34785.086113.0,33998.0,33998.0,86113.03

555556.0,888889.0,555556.0774596.0,000000.0,774596.02

1,157735.0,57735.01

)()(

43210

43210

3210

3210

210

210

10

10

0

1

1

cccccxxxxxn

ccccxxxxn

cccxxxn

ccxxn

xfcdxxfn

iii

Page 54: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 54

Error Analysis for Gauss Quadrature

12norder of spolynomial allfor exact be willformula The

]1,1[),()!22()32(

)!1(2Error

:satisfieserror true theThen,formula, Quadrature Gauss the

toaccording selected are

)()(

:by edapproximat be)( integral theLet

)22(3

432n

0

n

ii

n

iii

b

a

b

a

fnn

n

xandcwhere

xfcdxxf

dxxf

Page 55: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 55

Example1.n with QuadratureGaussian using

1

0

2

dxeEvaluate x

b? and a arbitrary for

)(:compute toformula theuse wedo How

31

31)(

1

1

b

adxxf

ffdxxf

1

1 222)( dtabtabfabdxxf

b

a

Page 56: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 56

Example

22

22

5.315.05.

315.0

1

15.5.1

0

21

21

ee

dtedxe tx

Page 57: CISE301 : Numerical Methods Topic 7 Numerical Integration  Lecture 24-27

CISE301_Topic7 KFUPM 57

Improper Integrals

1

0 221 2

1

1 2a

1111 :

function. new on the method apply the and

)0 assuming(,11)(

following thelikeation transforma Use)or is limits theof (one integralsimproper eapproximat

todirectly used benot can earlier discussed Methods

dt

tt

dxx

Example

abdtt

ft

dxxf a

b

b