lesson 31: numerical integration

38
. . . . . . Section 5.7 Numerical Integration Math 1a Introduction to Calculus April 25, 2008 Announcements Midterm III is Wednesday 4/30 in class (covers §4.9–5.6) Friday 5/2 is Movie Day! Final (tentative) 5/23 9:15am Problem Sessions Sunday, Thursday, 7pm, SC 310 Office hours Tues, Weds, 2–4pm SC 323

Upload: matthew-leingang

Post on 29-Nov-2014

4.204 views

Category:

Education


1 download

DESCRIPTION

Three methods for approximating an integral are surprisingly good: The Trapezoidal Rule, the Midpoint Rule, and Simpson's Rule.

TRANSCRIPT

Page 1: Lesson 31: Numerical Integration

. . . . . .

Section5.7NumericalIntegration

Math1aIntroductiontoCalculus

April25, 2008

Announcements

◮ MidtermIII isWednesday4/30inclass(covers§4.9–5.6)◮ Friday5/2isMovieDay!◮ Final(tentative)5/239:15am◮ ProblemSessionsSunday, Thursday, 7pm, SC 310◮ OfficehoursTues, Weds, 2–4pmSC 323

Page 2: Lesson 31: Numerical Integration

. . . . . .

Announcements

◮ MidtermIII isWednesday4/30inclass(covers§4.9–5.6)◮ Friday5/2isMovieDay!◮ Final(tentative)5/239:15am◮ ProblemSessionsSunday, Thursday, 7pm, SC 310◮ OfficehoursTues, Weds, 2–4pmSC 323

Page 3: Lesson 31: Numerical Integration

. . . . . .

Outline

LastTime: IntegrationbyParts

TheTrapezoidalRuleTrapezoidsinsteadofrectangles

TheMidpointRule

Simpson’sRule

ErrorestimatesfortheTrapezoidalandMidpointRules

ErrorestimatesforSimpson’sRule

Page 4: Lesson 31: Numerical Integration

. . . . . .

Theorem(IntegrationbyParts)Let u and v bedifferentiablefunctions. Then∫

u(x)v′(x)dx = u(x)v(x) −∫

v(x)u′(x)dx.

Succinctly, ∫udv = uv−

∫v du.

Theorem(IntegrationbyParts, definiteform)

∫ b

audv = uv

∣∣∣∣ba−

∫ b

av du.

Page 5: Lesson 31: Numerical Integration

. . . . . .

Theorem(IntegrationbyParts)Let u and v bedifferentiablefunctions. Then∫

u(x)v′(x)dx = u(x)v(x) −∫

v(x)u′(x)dx.

Succinctly, ∫udv = uv−

∫v du.

Theorem(IntegrationbyParts, definiteform)

∫ b

audv = uv

∣∣∣∣ba−

∫ b

av du.

Page 6: Lesson 31: Numerical Integration

. . . . . .

Outline

LastTime: IntegrationbyParts

TheTrapezoidalRuleTrapezoidsinsteadofrectangles

TheMidpointRule

Simpson’sRule

ErrorestimatesfortheTrapezoidalandMidpointRules

ErrorestimatesforSimpson’sRule

Page 7: Lesson 31: Numerical Integration

. . . . . .

WhyestimateanintegralwhenwehavetheFTC?

◮ Antidifferentiationis“hard”

◮ Sometimesantidifferentiationisimpossible

◮ Sometimesallweneedisanapproximation

◮ Thesemethodsactuallyworkprettywell!

Page 8: Lesson 31: Numerical Integration

. . . . . .

Trapezoidsinsteadofrectangles

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ Inthecaseofasimpledecreasingfunctionlikethisone, clearly Ln istoomuchand Rn isnotenough.

◮ Whynotaveragethemoutandmakeatrapezoid?

∆A =

f(xi−1) + f(xi)2

∆x

◮ Thesmallertheintervals, thebettertheapproximation

Page 9: Lesson 31: Numerical Integration

. . . . . .

Trapezoidsinsteadofrectangles

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ Inthecaseofasimpledecreasingfunctionlikethisone, clearly Ln istoomuchand Rn isnotenough.

◮ Whynotaveragethemoutandmakeatrapezoid?

∆A =

f(xi−1) + f(xi)2

∆x

◮ Thesmallertheintervals, thebettertheapproximation

Page 10: Lesson 31: Numerical Integration

. . . . . .

Trapezoidsinsteadofrectangles

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ Inthecaseofasimpledecreasingfunctionlikethisone, clearly Ln istoomuchand Rn isnotenough.

◮ Whynotaveragethemoutandmakeatrapezoid?

∆A =

f(xi−1) + f(xi)2

∆x

◮ Thesmallertheintervals, thebettertheapproximation

Page 11: Lesson 31: Numerical Integration

. . . . . .

Trapezoidsinsteadofrectangles

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ Inthecaseofasimpledecreasingfunctionlikethisone, clearly Ln istoomuchand Rn isnotenough.

◮ Whynotaveragethemoutandmakeatrapezoid?

∆A =f(xi−1) + f(xi)

2∆x

◮ Thesmallertheintervals, thebettertheapproximation

Page 12: Lesson 31: Numerical Integration

. . . . . .

Trapezoidsinsteadofrectangles

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ Inthecaseofasimpledecreasingfunctionlikethisone, clearly Ln istoomuchand Rn isnotenough.

◮ Whynotaveragethemoutandmakeatrapezoid?

∆A =f(xi−1) + f(xi)

2∆x

◮ Thesmallertheintervals, thebettertheapproximation

Page 13: Lesson 31: Numerical Integration

. . . . . .

TheTrapezoidalRule

DefinitionDividetheinterval [a,b] upinto n pieces. Let ∆x =

b− an

,

xi = a + i∆x, and yi = f(xi) foreach i from 1 to n.

The (n + 1)-point TrapezoidalRule approximationto∫ b

af(x)dx

isgivenby

Tn(f) =n∑i=1

f(xi−1) + f(xi)2

∆x

= ∆x[y0 + y1

2+

y1 + y22

+ · · · +yn−1 + yn

2

]=

∆x2

(y0 + 2y1 + 2y2 + · · · + 2yn−1 + yn

)

Page 14: Lesson 31: Numerical Integration

. . . . . .

Example

Example

Estimate∫ 1

0x2 dx withtheTrapezoidalRuleand n = 4.

SolutionThesetofvaluesis{

y0, y1, y2, y3, y4}

={0,

(14

)2,(24

)2,(34

)2,(44

)2}So

Tn(f) =1

2 · 4

(0 + 2 · 1

16+ 2 · 4

16+ 2 · 9

16+

1616

)=

18

(2 + 8 + 18 + 16

16

)=

44128

=1132

Page 15: Lesson 31: Numerical Integration

. . . . . .

Example

Example

Estimate∫ 1

0x2 dx withtheTrapezoidalRuleand n = 4.

SolutionThesetofvaluesis{

y0, y1, y2, y3, y4}

={0,

(14

)2,(24

)2,(34

)2,(44

)2}So

Tn(f) =1

2 · 4

(0 + 2 · 1

16+ 2 · 4

16+ 2 · 9

16+

1616

)=

18

(2 + 8 + 18 + 16

16

)=

44128

=1132

Page 16: Lesson 31: Numerical Integration

. . . . . .

YourTurn

ExampleEstimate

ln 2 =

∫ 2

1

1xdx

withtheTrapezoidalRuleand n = 8.

Solution0.694122

Page 17: Lesson 31: Numerical Integration

. . . . . .

YourTurn

ExampleEstimate

ln 2 =

∫ 2

1

1xdx

withtheTrapezoidalRuleand n = 8.

Solution0.694122

Page 18: Lesson 31: Numerical Integration

. . . . . .

Outline

LastTime: IntegrationbyParts

TheTrapezoidalRuleTrapezoidsinsteadofrectangles

TheMidpointRule

Simpson’sRule

ErrorestimatesfortheTrapezoidalandMidpointRules

ErrorestimatesforSimpson’sRule

Page 19: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A =

f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 20: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A =

f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 21: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A =

f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 22: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A =

f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 23: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A = f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 24: Lesson 31: Numerical Integration

. . . . . .

Midpointstocancelouttheslop

..xi−1 .xi

.f(xi−1)

.f(xi)

◮ TheTrapezoidalRuleaveragesthevalues

◮ Anotherpossibilitywouldbetoaveragethepoints.

∆A = f(xi−1 + xi

2

)∆x

◮ Again, thesmallertheintervals, thebettertheapproximation

Page 25: Lesson 31: Numerical Integration

. . . . . .

TheMidpointRule

DefinitionDividetheinterval [a,b] upinto n pieces. Let ∆x =

b− an

, and

xi = a + i∆x foreach i from 1 to n.

The (n + 1)-point MidpointRule approximationto∫ b

af(x)dx is

givenby

Mn(f) =n∑i=1

f(xi−1 + xi

2

)∆x

= ∆x(f(x0 + x1

2

)+ f

(x1 + x2

2

)+ · · · + f

(xn−1 + xn

2

))

Page 26: Lesson 31: Numerical Integration

. . . . . .

Example

Example

Estimate∫ 1

0x2 dx withtheMidpointRuleand n = 4.

SolutionThesetofmidpointsis {

0, 18 ,38 ,

58 ,

78

}So

Mn(f) =14

(0 +

(18

)2+

(38

)2+

(58

)2+

(78

)2)=

14

(1 + 9 + 25 + 49

64

)=

84256

=2164

.

Page 27: Lesson 31: Numerical Integration

. . . . . .

Example

Example

Estimate∫ 1

0x2 dx withtheMidpointRuleand n = 4.

SolutionThesetofmidpointsis {

0, 18 ,38 ,

58 ,

78

}So

Mn(f) =14

(0 +

(18

)2+

(38

)2+

(58

)2+

(78

)2)=

14

(1 + 9 + 25 + 49

64

)=

84256

=2164

.

Page 28: Lesson 31: Numerical Integration

. . . . . .

YourTurn

ExampleEstimate

ln 2 =

∫ 2

1

1xdx

withtheMidpointRuleand n = 8.

Solution0.692661

Page 29: Lesson 31: Numerical Integration

. . . . . .

YourTurn

ExampleEstimate

ln 2 =

∫ 2

1

1xdx

withtheMidpointRuleand n = 8.

Solution0.692661

Page 30: Lesson 31: Numerical Integration

. . . . . .

Outline

LastTime: IntegrationbyParts

TheTrapezoidalRuleTrapezoidsinsteadofrectangles

TheMidpointRule

Simpson’sRule

ErrorestimatesfortheTrapezoidalandMidpointRules

ErrorestimatesforSimpson’sRule

Page 31: Lesson 31: Numerical Integration

. . . . . .

Parabolasinsteadoflines

.

◮ TrapezoidalRuleapproximatesthefunctionwithaline

◮ Whynotuseaparabola?◮ A sectionofaparabolapassingthroughequallyspacedpointsis

∆x3

(y0 + 4y1 + y2)

◮ needanevennumberofpoints

Page 32: Lesson 31: Numerical Integration

. . . . . .

Simpson’sRule

DefinitionDividetheinterval [a,b] upinto n pieces, where n iseven. Let

∆x =b− an

, xi = a + i∆x, and yi = f(xi) foreach i from 1 to n.

The (n + 1)-point Simpson’sRule approximationto∫ b

af(x)dx is

givenby

Sn(f) =

n/2∑i=1

∆x3

(y2i + 4y2i+1 + y2i+2

)=

b− a3n

(y0 + 4y1 + 2y2 + 4y3 + · · · + 2yn−2 + 4yn−1 + yn

)

Page 33: Lesson 31: Numerical Integration

. . . . . .

MeettheSimpsons

ThomasSimpson(1710-1761)

HomerSimpson

Page 34: Lesson 31: Numerical Integration

. . . . . .

Examples

Example

UseSimpson’srulewith n = 4 toestimate∫ 1

0x2 dx

Solution{y0, y1, y2, y3, y4

}=

{0,

(14

)2,(24

)2,(34

)2,(44

)2}So

S4(f) =1

3 · 4

(0 + 4 · 1

16+ 2 · 4

16+ 4 · 9

16+

1616

)=

112

(4 + 8 + 36 + 16

16

)=

112

· 6416

=13

Nosurprisewegettheexactvalue; approximatingaparabolawithaparabolashouldbeexact!

Page 35: Lesson 31: Numerical Integration

. . . . . .

Examples

Example

UseSimpson’srulewith n = 4 toestimate∫ 1

0x2 dx

Solution{y0, y1, y2, y3, y4

}=

{0,

(14

)2,(24

)2,(34

)2,(44

)2}So

S4(f) =1

3 · 4

(0 + 4 · 1

16+ 2 · 4

16+ 4 · 9

16+

1616

)=

112

(4 + 8 + 36 + 16

16

)=

112

· 6416

=13

Nosurprisewegettheexactvalue; approximatingaparabolawithaparabolashouldbeexact!

Page 36: Lesson 31: Numerical Integration

. . . . . .

Examples

Example

UseSimpson’srulewith n = 4 toestimate∫ 1

0x2 dx

Solution{y0, y1, y2, y3, y4

}=

{0,

(14

)2,(24

)2,(34

)2,(44

)2}So

S4(f) =1

3 · 4

(0 + 4 · 1

16+ 2 · 4

16+ 4 · 9

16+

1616

)=

112

(4 + 8 + 36 + 16

16

)=

112

· 6416

=13

Nosurprisewegettheexactvalue; approximatingaparabolawithaparabolashouldbeexact!

Page 37: Lesson 31: Numerical Integration

. . . . . .

Yourturn

ExampleUseSimpson’sRulewith n = 8 toestimate ln 2.

Solution0.693155

Page 38: Lesson 31: Numerical Integration

. . . . . .

Yourturn

ExampleUseSimpson’sRulewith n = 8 toestimate ln 2.

Solution0.693155