3 2 1 b a b a x f x f 3 x f 3 x f 8 h 3 3 a b h Lxdx fxdx Truncation error 3 a

# 3 2 1 b a b a x f x f 3 x f 3 x f 8 h 3 3 a b h lxdx

This preview shows page 43 - 56 out of 61 pages.

3 2 1 0 b a b a x f x f 3 x f 3 x f 8 h 3 3 a b h ; L(x)dx f(x)dx + + + = - = Truncation error 3 a b h ; f 6480 a b f h 80 3 E 4 5 4 5 t - = - - = - = ) ( ) ( ) ( ) ( ) ( ξ ξ
Example: Simpson’s Rules Example: Simpson’s Rules Evaluate the integral Simpson’s 1/3-Rule Simpson’s 3/8-Rule dx xe 4 0 x 2 [ ] [ ] % . . . . . ) ( ) ( ) ( ) ( 96 57 926 5216 411 8240 926 5216 411 8240 e 4 e 2 4 0 3 2 4 f 2 f 4 0 f 3 h dx xe I 8 4 4 0 x 2 - = - = = + + = + + = ε [ ] % 71 . 30 926 . 5216 209 . 6819 926 . 5216 209 . 6819 832 . 11923 ) 33933 . 552 ( 3 ) 18922 . 19 ( 3 0 8 ) 4/3 ( 3 ) 4 ( f ) 3 8 ( f 3 ) 3 4 ( f 3 ) 0 ( f 8 h 3 dx xe I 4 0 x 2 - = - = = + + + = + + + = ε
function I = Simp(f, a, b, n) % integral of f using composite Simpson rule % n must be even h = (b - a)/n; S = feval(f,a); for i = 1 : 2 : n-1 x(i) = a + h*i; S = S + 4*feval(f, x(i)); end for i = 2 : 2 : n-2 x(i) = a + h*i; S = S + 2*feval(f, x(i)); end S = S + feval(f, b); I = h*S/3; Composite Simpson’s Rule Composite Simpson’s Rule
Simpson’s Rule Simpson’s Rule
Composite Simpson’s Rule Composite Simpson’s Rule
» x=0:0.04:4; y=example(x); » x1=0:2:4; y1=example(x1); » c=Lagrange_coef(x1,y1); p1=Lagrange_eval(x,x1,c); » H=plot(x,y,x1,y1, 'r*' ,x,p1, 'r' ); » xlabel('x'); ylabel('y'); title('f(x) = x*exp(2x)'); » set(H,'LineWidth',3,'MarkerSize',12); » x2=0:1:4; y2=example(x2); » c=Lagrange_coef(x2,y2); p2=Lagrange_eval(x,x2,c); » H=plot(x,y,x2,y2, 'r*' ,x,p2, 'r' ); » xlabel( 'x' ); ylabel( 'y' ); title( 'f(x) = x*exp(2x)' ); » set(H, 'LineWidth' ,3, 'MarkerSize' ,12); » » I=Simp( 'example' ,0,4,2) I = 8.2404e+003 » I=Simp( 'example' ,0,4,4) I = 5.6710e+003 » I=Simp( 'example' ,0,4,8) I = 5.2568e+003 » I=Simp( 'example' ,0,4,16) I = 5.2197e+003 » Q=Quad8( 'example' ,0,4) Q = 5.2169e+003 n = 2 n = 4 n = 8 n = 16 MATLAB fun
Multiple applications of Simpson’s rule Multiple applications of Simpson’s rule with odd number of intervals with odd number of intervals Hybrid Simpson’s 1/3 & 3/8 rules
Newton-Cotes Closed Newton-Cotes Closed Integration Formulae Integration Formulae ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ' ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ξ ξ ξ ξ ξ 6 7 5 4 3 2 1 0 6 7 4 3 2 1 0 4 5 3 2 1 0 4 5 2 1 0 3 1 0 f h 12096 275 288 x f 19 x f 75 x f 50 x f 50 x f 75 x f 19 a b 5 f h 945 8 90 x f 7 x f 32 x f 12 x f 32 x f 7 a b rule s Boole' 4 f h 80 3 8 x f x f 3 x f 3 x f a b rule 3/8 s Simpson' 3 f h 90 1 6 x f x f 4 x f a b rule 1/3 s Simpson 2 f h 12 1 2 x f x f a b rule l Trapezoida 1 Error Truncation Formula Name n - + + + + + - - + + + + - - + + + - - + + - - + - n a b h - =
Composite Trapezoidal Rule with Composite Trapezoidal Rule with Unequal Segments Unequal Segments Evaluate the integral h 1 = 2, h 2 = 1, h 3 = 0.5, h 4 = 0.5 dx xe I 4 0 x 2 = [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] % . . . . ) ( ) . ( ) . ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( . . 45 14 58 5971 e 4 e 5 3 2 0.5 e 5 3 3e 2 0.5 e 3 e 2 2 1 e 2 0 2 2 4 f 5 3 f 2 h 5 3 f 3 f 2 h 3 f 2 f 2 h 2 f 0 f 2 h dx x f dx x f dx x f dx x f I 8 7 7 6 6 4 4 4 3 2 1 4 5 3 5 3 3 3 2 2 0 - = = + + + + + + + = + + + + + + + = + + + = ε
Trapezoidal Rule for Unequally Spaced Data Trapezoidal Rule for Unequally Spaced Data
MATLAB Function: MATLAB Function: trapz trapz » x=[0 1 1.5 2.0 2.5 3.0 3.3 3.6 3.8 3.9 4.0] x = Columns 1 through 7 0 1.0000 1.5000 2.0000 2.5000 3.0000 3.3000 Columns 8 through 11 3.6000 3.8000 3.9000 4.0000 » y=x.*exp(2.*x) y = 1.0e+004 * Columns 1 through 7 0 0.0007 0.0030 0.0109 0.0371 0.1210 0.2426 Columns 8 through 11 0.4822 0.7593 0.9518 1.1924 » integr = trapz(x,y) integr = 5.3651e+003 Z = trapz(x,y)
Integral of Unevenly-Spaced Data Integral of Unevenly-Spaced Data Trapezoidal rule Could also be evaluated with Simpson’s rule for higher accuracy
Composite Simpson’s Rule with Composite Simpson’s Rule with Unequal Segments Unequal Segments

#### You've reached the end of your free preview.

Want to read all 61 pages?