Presentation is loading. Please wait.

Presentation is loading. Please wait.

Quadrature. 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule.

Similar presentations


Presentation on theme: "Quadrature. 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule."— Presentation transcript:

1 Quadrature

2 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule

3

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

5 #include #define TRUE 1 struct 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); }

6 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)* ; return( func_v ); }

7 a = 0;b = 1; M = 10; H = (b-a)/M; % 2M intervals x = 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

8 quad 基于变步长 Simpson 公式 (recursive adaptive Simpson quadrature) quad8 基于 Newton-Cotes 公式 (adaptive recursive Newton-Cotes 8 panel rule) quadl adaptive Lobatto quadrature % 1 f = inline('sin(x)/x'); f = vectorize(f); Q = quad(f,realmin,pi) % 2 anonymous function, beginning with MATLAB 7 f sin(x)/x Q = quad(f,realmin,pi) % 3 use an M-file Q =

9 Dblquad 二重积分 Triplequad 三重积分 计算 %1 function f = fxy(x,y) f = exp(-x.^2/2).*sin(x.^2+y.^2); I = dblquad('fxy',-2,2,-1,1) %2 I = dblquad(inline('exp(-x.^2/2).*sin(x.^2+y.^2)','x','y'),-2,2,-1,1) 符号计算 int

10 % integrating discrete data x = 0:10; y = x; % composite trapezoid rule T = sum(diff(x).*(y(1:end-1)+y(2:end))/2)

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

12 是正交多项式的实根, 定理: 其中 是权函数,

13 三项递推:

14

15 勒让德多项式 (Legendre) [-1,1],  (x)=1 递推关系 : P 0 (x)=1, P 1 (x)=x,

16 Legendre 多项式

17 Christoffel-Darboux identity 设 则 对 Legendre 多项式

18 T n (x)=cos(narccosx) 切比雪夫多项式 (Chebyshev) 递推关系 : T 0 (x)=1, T 1 (x)=x, T 2 (x)=2x 2 -1, T 3 (x)= 4x 3 -3x,………

19 埃尔米特多项式 (Hermite) (- ,+  ),  (x)=e -x 2 Hermite 多项式的三项递推关系

20 拉盖尔多项式 (Laguerre) [0,+  ),  (x)=e -x Laguerre 多项式的三项递推关系

21 无穷积分 令 Gauss-Laguerre 方法 ( 定义在 [0,∞), 无复合公式 )

22 区间 [ x i, x i +1 ], s=x-x i, h=h i = x i+1 - x i 补充 : 分段多项式插值 三阶 Hermite 插值

23 区间 [ x i, x i +1 ]

24 三次样条插值

25 区间 [ x i, x i +1 ], s=x-x i, y i =f(x i ), d i =f’(x i ) 区间 [ x i-1, x i ],

26 端点条件 : 1. 固定斜率 2. 自然端点 3. 非节点 代入 d 3

27 The road to wisdom? Well, it’s plain and simple to express: Err and err and err again but less and less PIET HEIN, Grooks(1966)


Download ppt "Quadrature. 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule."

Similar presentations


Ads by Google