Piecewise Quadratic approximations h x 3 x 1 x n 1 Composite Simpsons 13 Rule

# Piecewise quadratic approximations h x 3 x 1 x n 1

This preview shows page 16 - 27 out of 31 pages.

Piecewise Quadratic approximations h x 3 x 1 x n-1
Composite Simpson’s 1/3 Rule Applicable only if the number of segments is even
Composite Simpson’s 1/3 Rule Applicable only if the number of segments is even Substitute Simpson’s 1/3 rule for each integral For uniform spacing (equal segments) - + + + = n 2 n 4 2 2 0 x x x x x x dx x f dx x f dx x f I ) ( ) ( ) ( 6 x f x f 4 x f h 2 6 x f x f 4 x f h 2 6 x f x f 4 x f h 2 I n 1 n 2 n 4 3 2 2 1 0 ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( + + + + + + + + + = - - + + + - = - = - = 1 n 5 3 1 i 2 n 6 4 2 j n j i 0 x f x f 2 x f 4 x f n 3 a b I , , , , ) ( ) ( ) ( ) ( ) (
Simpson’s 1/3 Rule Truncation error (single application) Exact up to cubic polynomial ( f ( 4 ) = 0) Approximate error for multiple applications 2 a b h ; f 2880 a b f h 90 1 E 4 5 4 5 t - = - - = - = ) ( ) ( ) ( ) ( ) ( ξ ξ f n 180 a b E 4 4 3 a ) ( ) ( - - =
Composite Simpson’s 1/3 Rule Evaluate the integral n = 2, h = 2 n = 4, h = 1 dx xe I 4 0 x 2 = [ ] [ ] % . . ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( 70 8 975 5670 e 4 e 3 4 e 2 2 e 4 0 3 1 4 f 3 f 4 2 f 2 1 f 4 0 f 3 h I 8 6 4 2 - = = + + + + = + + + + = ε [ ] [ ] % . . ) ( ) ( ) ( ) ( 96 57 411 8240 e 4 e 2 4 0 3 2 4 f 2 f 4 0 f 3 h I 8 4 - = = + + = + + = ε
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 1/3 Rule
Simpson’s 1/3 Rule
Composite Simpson’s 1/3 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 with odd number of intervals Hybrid Simpson’s 1/3 & 3/8 rules
Newton-Cotes Closed Integration Formulae ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ' ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ξ ξ ξ ξ ξ 6 7 5 4 3 2 1 0 6 7 4 3 2 1 0 4 5 3 2

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

Want to read all 31 pages?

• Spring '09
• RAPHAELHAFTKA
• dx, Romberg's method, Composite Simpson