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

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

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

#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); }

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 ); }

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

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

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

Legendre 多项式

Christoffel-Darboux identity 设 则 对 Legendre 多项式

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,………

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)