數值方法 2008, applied mathematics ndhu 1 simpson rule composite simpson rule

24
數數數數 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

Upload: ethelbert-poole

Post on 26-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 1

Simpson ruleComposite Simpson rule

Page 2: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 2

Simpson rule for numerical integration

b

aab

fbf

bafaf

abdxxf

baCf

5)4(

4

)(2880

)()()

2(4)(

6)(

withexists b)(a,in number a then ],,[ If

Page 3: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 3

a=1.2;b=2;x=linspace(a,b);plot(x,sin(x));hold on

y=sin(x) for x within [1.2 2]

Page 4: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 4

Quadratic polynomial

c=0.5*(a+b);x=[a b c]; y=sin(x);p=polyfit(x,y,2);z=linspace(a,b);plot(z,polyval(p,z) ,'r')

• Approximate sin using a quadratic polynomial

Page 5: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 5

a=1;b=3;x=linspace(a,b);plot(x,sin(x))hold on;c=0.5*(a+b);x=[a b c]; y=sin(x);p=polyfit(x,y,2);z=linspace(a,b);plot(z,polyval(p,z) ,'r')

Approximate sin(x) within [1 3] by a quadratic polynomial

Page 6: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 6

a=1;b=3;x=linspace(a,b);plot(x,sin(x))hold on;c=0.5*(a+b);x=[a b ]; y=sin(x);p=polyfit(x,y,1);z=linspace(a,b);plot(z,polyval(p,z) ,'r')

Approximate sin(x) within [1 3] by a line

1 1.5 2 2.5 30.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 7: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 7

1 1.5 2 2.5 30.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Strategy I : Apply Trapezoid rule to calculate area under a lineStrategy II : Apply Simpson rule to calculate area under a second order polynomial

Strategy II is more accurate and general than strategy I, since a line is a special case of quadratic polynomial

Page 8: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 8

Simpson rule

Original task: integration of f(x) within [a,b]

c=(a+b)/2 Numerical task

Approximate f(x) within [a,b] by a quadratic polynomial, p(x)

Integration of p(x) within [a,b]

Page 9: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 9

Blue: f(x)=sin(x) within [1,3] Red: a quadratic polynomial that pass (1,sin(1)), (2,sin(2)),(3,sin(3))

Page 10: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 10

))2

()((23

a-b

Area(I)

abfaf

3

ab

))2

()2

((23

a-b

Area(II)

abf

abf

))()2

((23

a-b

Area(III)

bfab

f

2

ab

• The area under a quadratic polynomial is a sum of area I, II and III

Page 11: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 11

• The area under a quadratic polynomial is a sum of area I, II and III

• Partition [a,b] to three equal-size intervals, and use the high of the middle point c to produce three Trapezoids

• Use the composite Trapezoid rule to determine area I, II and III h/2*(f(a)+f(c) +f(c)+f(c)+ f(c)+f(b)) • substitute h=(b-a)/3 and c=(a+b)/2• area I + II + III = (b-a)/6 *(f(a)+4*f((a+b)/2) +f(b))

Page 12: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 12

))2

()((23

a-b

Area(I)

abfaf

3

ab

))2

()2

((23

a-b

Area(II)

abf

abf

))()2

((23

a-b

Area(III)

bfab

f

))()2

(4)((23

a-b

Area(III)Area(II)Area(I)

bfab

faf

2

ab

Page 13: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 13

passes )(

)( 2

xp

Pxp ))(,( bfb ))

2(,

2(

baf

ba

b

adxxp )(

that Show

)()

2(4)(

6bf

bafaf

ab

))(,( afa

Page 14: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 14

)()()( :

))((

))(()(

))((

))(()(

))((

))(()( )(

cf,p(c)bf,p(b)afp(a)proof

bcac

bxaxcf

cbab

cxaxbf

caba

cxbxafxp

))(,( afa

))(,( bfb

2)),(,(

baccfc

Page 15: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 15

3

1

)02)(12(

)1)(0(

))((

))((

3

4

)01)(21(

)2)(0(

))((

))((

3

1

)10)(20(

)1)(2(

))((

))(2(

))((

))((

2

))((

))(()(

))((

))(()(

))((

))(()(

))((

))(()(

))((

))(()(

))((

))(()( )(

2

0

2

0

2

0

2

hdttt

hdxcbab

cxax

hdttt

hdxbcac

bxax

hdttt

hdxcaba

haxhaxdx

caba

cxbx

hac

hab

dxbcac

bxaxcfdx

cbab

cxaxbfdx

caba

cxbxaf

dxbcac

bxaxcf

cbab

cxaxbf

caba

cxbxafdxxp

b

a

b

a

ha

a

b

a

b

a

b

a

b

a

b

a

b

a

))()(4)((

3bfcfaf

h

))()(4)((6

)(

))()(4)((3

bfcfafab

bfcfafh

Page 16: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 16

dttt

hdthh

htht

dxcaba

haxhaxdx

caba

cxbx

h

ha

a

b

a

2

0

2

0

2

)10)(20(

)0)(2(

)0)(20(

))(2(

))((

))(2(

))((

))((

-1 -0.5 0 0.5 1 1.5 2 2.5 3-0.5

0

0.5

1

1.5

2

2.5

3

Shift Lagrange polynomialRescale Lagrange polynomial

Page 17: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 17

Shortcut to Simpson 1/3 rule

))()2

(4)((6

)()()()(

)(

2

2

bfba

fafab

IIIQIIQIQdxxp

Pp

CBxAxxp

b

a

1. Partition [a,b] to three equal intervals2. Draw three trapezoids, Q(I), Q(II) and Q(III)3. Calculate the sum of areas of the three trapezoids

Page 18: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 18

Proof

))()2

(4)((6

23

)()(

))()((4))()((2))()((2)(

1)(

23

2

2

2

2

bfba

fafab

CxxB

xA

dxCBxAxdxxp

Pp

CBxAx

bxaxcfcxaxbfcxbxafba

xp

b

a

b

a

b

a

Page 19: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU

19

Composite Simpson rule

Partition [a,b] into n interval Integrate each interval by Simpson

rule h=(b-a)/2n

1

0

)22(

2)(

)(

n

i

hia

iha

b

a

dxxf

dxxf

Page 20: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 20

Apply Simpson sule to each interval

)))22(())12((4)2((3

)()22(

2

hiafhiafihafh

dxxfhia

iha

))()2

(4)((6

)(

bfba

fafab

dxxpb

a

Page 21: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 21

Composite Simpson rule

1

0

1

0

)22(

2

)))22(())12((4)2((3

)()(

n

i

n

i

hia

iha

b

a

hiafhiafihafh

dxxfdxxf

Page 22: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 22

1

0

1

0

)22(

2

)))22(())12((4)2((3

)()(

n

i

n

i

hia

iha

b

a

hiafhiafihafh

dxxfdxxf

Set nSet fx

h=(b-a)/(2*n)ans=0;

for i=0:n-1

aa=a+2*i*h;cc=aa+h;bb=cc+h;

ans=ans+h/3*(fx(aa)+4*fx(cc)+fx(bb))

exit

Page 23: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 23

Composite Simpson rule

1

112

1

12

23210

1

0

)(3

4)(

3

2))()((

3

)(...)(4)(2)(4)(3

)))22(())12((4)2((3

)(

2,...,1,0,

n

kk

n

kk

n

n

i

b

a

k

xfh

xfh

bfafh

xfxfxfxfxfh

hiafhiafihafh

dxxf

njjhax h=(b-a)/2n

Page 24: 數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule

數值方法2008, Applied Mathematics NDHU 24

Composite Simpson rule

1

112

1

12 )(

3

4)(

3

2))()((

3

)(

2,...,1,0,

n

kk

n

kk

b

a

k

xfh

xfh

bfafh

dxxf

njjhax h=(b-a)/2n

Simpson's Rule for Numerical Integration