Download ppt - 08 numerical integration

Transcript
Page 1: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Numerical Integration

Page 2: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Objectives

• The student should be able to– Understand the need for numerical integration– Derive the trapezoidal rule using linear

interpolation– Apply the trapezoidal rule– Derive Simpson’s rule using parabolic

interpolation– Apply Simpson’s rule

Page 3: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Need for Numerical Integration!

6

1101

2

1

3

1

231

1

0

231

0

2

x

xxdxxxI

11

0

1

0

1 eedxeI xx

1

0

2

dxeI x

Page 4: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Interpolation!

• If we have a function that needs to be integrated between two points

• We may use an approximate form of the function to integrate!

• Polynomials are always integrable• Why don’t we use a polynomial to

approximate the function, then evaluate the integral

Page 5: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• To perform the definite integration of the function between (x0 & x1), we may interpolate the function between the two points as a line.

001

010 xx

xx

yyyxf

Page 6: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• Performing the integration on the approximate function:

1

0

1

0

001

010

x

x

x

x

dxxxxx

yyydxxfI

1

0

0

2

01

010 2

x

x

xxx

xx

yyxyI

Page 7: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• Performing the integration on the approximate function:

00

20

01

010010

21

01

0110 22

xxx

xx

yyxyxx

x

xx

yyxyI

2

0101

yyxxI

• Which is equivalent to the area of the trapezium!

Page 8: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

The Trapezoidal Rule

2

0101

yyxxI

2

2

1212

0101

yyxx

yyxxI

Integrating from x0 to x2:

Page 9: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

General Trapezoidal Rule

• For all the points equally separated(xi+1-xi=h)

• We may write the equation of the previous slide:

321

2323

1212

22

22

yyyh

yyxx

yyxxI

Page 10: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

In general

n

n

ii yyy

hI

1

10 2

2

Where n is the number if intervals and h=total interval/n

Page 11: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• Integrate• Using the trapezoidal

rule• Use 2 points and

compare with the result using 3 points

1

0

2dxxI

Page 12: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Solution

• Using 2 points (n=1), h=(1-0)/(1)=1

• Substituting:

212

1yyI

5.0102

1I

Page 13: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Solution

• Using 3 points (n=2), h=(1-0)/(2)=0.5

• Substituting:

321 22

5.0yyyI

375.0125.0*202

5.0I

Page 14: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Quadratic Interpolation

• If we get to interpolate a quadratic equation between every neighboring 3 points, we may use Newton’s interpolation formula:

103021 xxxxbxxbbxf

10102

3021 xxxxxxbxxbbxf

Page 15: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Integrating

10102

3021 xxxxxxbxxbbxf

2

0

2

0

10102

3021

x

x

x

x

dxxxxxxxbxxbbdxxf

2

0

2

0

10

2

10

3

30

2

21 232

x

x

x

x

xxxx

xxx

bxxx

bxbdxxf

Page 16: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

After substitutions and manipulation!

210 43

2

0

yyyh

dxxfx

x

Page 17: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

For 4-Intervals

23210 4243

4

0

yyyyyh

dxxfx

x

Page 18: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

In General: Simpson’s Rule

n

n

ii

n

ii

x

x

yyyyh

dxxfn 2

,..4,2

1

,..3,10 24

30

NOTE: the number of intervals HAS TO BE even

Page 19: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Example

• Integrate• Using the Simpson

rule• Use 3 points

1

0

2dxxI

Page 20: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Solution

• Using 3 points (n=2), h=(1-0)/(2)=0.5

• Substituting:

• Which is the exact solution!

210 43

5.0yyyI

3

1125.0*40

3

5.0I

Page 21: 08 numerical integration

ENEM602 Spring 2007

Dr. Eng. Mohammad Tawfik

Homework #7

• Chapter 21, pp. 610-612, numbers:21.1, 21.3, 21.5, 21.25, 21.28.

• Due date: Week 8-12 May 2005


Recommended