quadrature

27
Quadratur e

Upload: montgomery-arjun

Post on 30-Dec-2015

66 views

Category:

Documents


0 download

DESCRIPTION

Quadrature. 二阶 : 中点公式 :. 梯形公式 :. 四阶公式 :. Simpson’s 1/3 rd Rule. Boole ’ s rule,The 6-th Newton-Cotes rule (the first step of Romberg integration) The extrapolated Simpson ’ s rule. #include #include #include #define TRUE 1 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Quadrature

Quadrature

Page 2: Quadrature

b

adxxf )(

2

bahfM

2

)()( bfafhT

二阶 :中点公式 :

梯形公式 :

TMS

MSTS

3

1

3

2

)(2

)()(4)(6

bfcfafh

S 2

bac

四阶公式 :

Simpson’s 1/3rd Rule

abh

Page 3: Quadrature

6

)()(4)(2)( 210 xfxfxf

hdxxfb

a

...6

)()(4)(2 432

xfxfxf

h

6

)()(4)(2 234 nnn xfxfxf

h

6

)()(4)(2 12 nnn xfxfxf

h

b

a

dx)x(f ...)x(f...)x(f)x(f)x(fh

n 1310 43

)}]()(...)()(2... 242 nn xfxfxfxf

)()(2)(4)(3

2

2

1

10 n

n

evenii

i

n

oddii

i xfxfxfxfh

)()(2)(4)(3

2

2

1

10 n

n

evenii

i

n

oddii

i xfxfxfxfn

ab

n

abh

Page 4: Quadrature

)()(4)(2)(4)(122 bfefcfdfafh

S

2

cad

2

bce

)(2 24 SQSQ

15/)( 22 SSSQ

abh

Boole’s rule,The 6-th Newton-Cotes rule(the first step of Romberg integration)The extrapolated Simpson’s rule.

)()(7)(32)(12)(32)(790

7hObfefcfdfafh

Q

Page 5: Quadrature

#include <stdio.h>#include <stdlib.h>#include <math.h>#define TRUE 1struct t_bc{float a, b, h;} bc;

void main(){ int isimp, k, n; float s;void simps(), trapz();

printf( "\nComputer Soft/C7-1 Trapezoidal/Simpson's Rule \n\n" );

while( TRUE ){ printf( "Type 0 for trapezoidal, or 1 for Simpson's\n " ); scanf( "%d", &isimp ); printf( "Number of intervals ? " ); scanf( "%d", &n ); printf( "Lower limit of integration? " ); scanf( "%f", &bc.a ); printf( "Upper limit of integration? " ); scanf( "%f", &bc.b ); bc.h = (bc.b - bc.a)/n; if( isimp == 0 ){ trapz( &s, n ); /*-- Trapezoidal rule */ } else{ simps( &s, n ); /*-- Simpson's rule */ } printf( "-----------------------------------------\n" ); printf( " Result = %g \n", s ); printf( "-----------------------------------------\n" ); printf( "\nType 1 to continue, or 0 to stop.\n"); scanf( "%d", &k ); if( k != 1 ) exit(0); } }

Page 6: Quadrature

void simps(ss, n) /* Simpson's rule*/float *ss; int n;{ int i, ls; float sum, s, w, x;double func(); s = 0; sum = 0; if( n/2*2 == n ) ls = 0; else { ls = 3; for( i = 0; i <= 3; i++ ) { /* Simpson's 3/8 rule if n is odd */ x = bc.a + bc.h*i; w = 3; if( i == 0 || i == 3 ) w = 1; sum = sum + w*func( x ); } sum = sum*bc.h*3/8L; if( n == 3 ) return; } for( i = 0; i <= (n - ls); i++ ){ /* Simpson's 1/3 rule */ x = bc.a + bc.h*(i + ls); w = 2; if( (int)( i/2 )*2 + 1 == i ) w = 4; if( i == 0 || i == n - ls ) w = 1; s = s + w*func( x ); } *ss = sum + s*bc.h/3; return;}

void trapz(ss, n) /* Trapezoidal rule */float *ss; int n;{ int i; float sum, w, x;double func(); sum = 0; for( i = 0; i <= n; i++ ){ x = bc.a + i*bc.h; w = 2; if( i == 0 || i == n ) w = 1; sum = sum + w*func( x ); } *ss = sum*bc.h/2; return;}

double func(x) float x;{ float func_v; func_v = pow(1 + pow(x/2, 2), 2)*3.14159; return( func_v );}

Page 7: Quadrature

a = 0;b = 1;M = 10;

H = (b-a)/M; % 2M intervalsx = linspace(a,b,M+1);fpm = feval('fquad',x);fpm(2:end-1) = 2*fpm(2:end-1);csq = H*sum(fpm)/6;

x = linspace(a+H/2,b-H/2,M);fpm = feval('fquad',x);

csq = csq + 4/6*H*sum(fpm);

Composite Simpson numerical integration

Page 8: Quadrature

quad 基于变步长 Simpson 公式 (recursive adaptive Simpson quadrature)

quad8 基于 Newton-Cotes 公式 (adaptive recursive Newton-Cotes 8 panel rule)

quadl adaptive Lobatto quadrature

% 1f = inline('sin(x)/x');f = vectorize(f);Q = quad(f,realmin,pi)

% 2 anonymous function, beginning with MATLAB 7f = @(x) sin(x)/xQ = quad(f,realmin,pi)

% 3 use an M-file Q = quad(@sinc,0,pi)

Page 9: Quadrature

Dblquad 二重积分Triplequad 三重积分

计算

1

1

2

2

222 )sin(

2

dxdyyxeIx

%1function f = fxy(x,y)f = exp(-x.^2/2).*sin(x.^2+y.^2);

I = dblquad('fxy',-2,2,-1,1)

%2I = dblquad(inline('exp(-x.^2/2).*sin(x.^2+y.^2)','x','y'),-2,2,-1,1)

符号计算 int

Page 10: Quadrature

1

1

1

2

n

k

kkk

yyhT

kkk xxh 1

% integrating discrete data

x = 0:10;y = x;

% composite trapezoid ruleT = sum(diff(x).*(y(1:end-1)+y(2:end))/2)

Page 11: Quadrature

b

adxxfx )()(

1)( x

21

1)(

xx

xex )(

2

)( xex

n 点求积公式若具有 2n-1 阶代数精度就成为 Gauss 型求积公式 .

Gauss-Legendre 公式

Gauss-Chebyshev 公式

Gauss-Laguerre 公式

Gauss-Hermite 公式

Page 12: Quadrature

是正交多项式的实根,

],[)( 2 baCxf N

)(,)!2(

)()()()(

2

)2(

1

bakN

ftfdxxfx

N

N

j

N

jj

b

a

jt

n

iinn txkxp

1

)()(

)(x

)()(

1'

1

1

jNjNN

Nj tptpk

k

定理:

其中

是权函数,

Page 13: Quadrature

),()()()( 21 xpcxpbxaxp jjjjjj

.1)(,0)(;,,2,1 01 xpxpNj

NNNNNNN

N

N axpxp

xp

xp

abac

a

aabac

aab

xp

xp

xp

x

/)(

0

0

0

)(

)(

)(

//

/1

0

/1//

0/1/

)(

)(

)(

1

2

1

22222

111

1

2

1

三项递推:

Page 14: Quadrature

NN

NNN

JDTD

1

112

221

11

1

.,/2/1

1

1

ii

iiiii aa

cab

NNN xpaxTxx epp )()/1()()(

Page 15: Quadrature

勒让德多项式 (Legendre)

[-1,1] , (x)=1

递推关系 :

P0(x)=1, P1(x)=x,

22 )1(!2

1)( x

dx

dxP

n

n

nn

)13()( 221

2 xxP

)35()( 321

3 xxxP

)()()( 11112

1 xPxxPxP nnn

nnn

n

nn .....3,2,1

Page 16: Quadrature

),(1

)(12

)( 21 xpn

nxp

n

nxxp nnn

012

120

03

20

3

1010

n

nn

n

T

Legendre 多项式

0

0

0

0

1

12

21

1

N

NN

J

,14 2

k

kk 1,,2,1 Nk

Page 17: Quadrature

1)()]([ jT

jj tt pp

jjj tJ qq T

NjjjjjTj qqq ),,,(,1 21 qqq

)(20

21 jjj tpq

.)()(

212

0

21

b

ajj

jj dxxq

tp

q

212 jj q

Christoffel-Darboux identity

对 Legendre 多项式

Page 18: Quadrature

Tn(x)=cos(narccosx)

切比雪夫多项式 (Chebyshev)

,1

1)(],1,1[

2xx

递推关系 :

T0(x)=1 , T1(x)=x , T2(x)=2x2-1 ,

T3(x)= 4x3-3x,………

nnxTxTxxT

xxTxT

nnn ....3,2,1),()(2)(

)(,1)(

11

10

Page 19: Quadrature

埃尔米特多项式 (Hermite)

(- ,+), (x)=e-x2

22)()1()( x

n

nxn

n edx

dexH

0

1

1 1

( ) 1,

( ) 2 ,

( ) 2 ( ) 2 ( ), 1, 2,...n n n

H x

H x x

H x xH x nH x n

Hermite 多项式的三项递推关系

Page 20: Quadrature

拉盖尔多项式 (Laguerre)

[0,+), (x)=e-x )()( xn

n

nx

n exdx

dexL

0

1

21 1

( ) 1,

( ) 1 ,

( ) (1 2 ) ( ) ( ), 1, 2,...n n n

L x

L x x

L x n x L x n L x n

Laguerre 多项式的三项递推关系

Page 21: Quadrature

dxxfI

0

)(

dxxfdxxfdxxfdxxfz

z

z

z

z 3

2

2

1

1

)()()()(00

dxxfIj

j

z

zj

1

)(

||||1

1

k

jjk II

n

jj

xj

xx xfecdxxfeedxxf j

100

)()()(

无穷积分

Gauss-Laguerre 方法 ( 定义在 [0,∞), 无复合公式 )

Page 22: Quadrature

)()(

)()(

)(23

)(23

)(

'2

2

1'

2

2

3

323

13

32

ii

iii

xfh

hssxf

h

hss

xfh

shshxf

h

shsxP

区间 [xi, xi+1], s=x-xi, h=hi= xi+1-xi

补充 :

分段多项式插值三阶 Hermite 插值

Page 23: Quadrature

32 )()()()( iiiiiiii xxxxxxxP

区间 [xi, xi+1]

21

1'

1'

1

1''

1

'

)(],[2)(

)()(2],[3

)(

)(

ii

iiiii

ii

iiiii

ii

ii

xx

xfxxfxf

xx

xfxfxxf

xf

xf

Page 24: Quadrature

2' )(3)(2)( iiiiii xxxxxP

三次样条插值

21

11

1

11

],[2

2],[3

?

)(

ii

iiiii

ii

iiiii

i

ii

xx

xxf

xx

xxf

xf

Page 25: Quadrature

iiiii dh

hssd

h

hssy

h

shshy

h

shsxP

2

2

12

2

3

323

13

32 )()(2323)(

区间 [xi, xi+1],

s=x-xi, yi=f(xi), di=f’(xi)

2

1" 4626126)(

h

dhsdhsshxP iii

i

ii

iii xx

yy

1

1

区间 [xi-1, xi],

i

iiiii h

ddxP

426)( 1"

i

iiiii h

ddxP

246)( 1

1"

1

11"1

246)(

i

iiiii h

ddxP

Page 26: Quadrature

)()( "1

" iiii xPxP

iiiiiiiiiii hhdhdhhdh 111111 32

iiiii ddd 334 111 1,,2 ni

端点条件 :

1.固定斜率

2.自然端点

3.非节点

0)( 1"

1 xP 111 32 dd 11 32 nnn dd

)()( 2'''

22'''

1 xPxP

21 322211 22 dddd

2121 542 dd代入 d3

Page 27: Quadrature

The road to wisdom?

Well, it’s plain and simple to express:

Err

and err

and err again

but less

and less

and less

PIET HEIN, Grooks(1966)