Download presentation
Presentation is loading. Please wait.
1
Chapter 17 Numerical Integration Formulas
3
Graphical Representation of Integral Integral = area under the curve Use of a grid to approximate an integral
4
Use of strips to approximate an integral
5
Numerical Integration Net force against a skyscraper Cross-sectional area and volume flowrate in a river Survey of land area of an irregular lot
6
Water exerting pressure on the upstream face of a dam: (a) side view showing force increasing linearly with depth; (b) front view showing width of dam in meters. Pressure Force on a Dam p = gh = h
7
Integration Weighted sum of functional values at discrete points Newton-Cotes closed or open formulae -- evenly spaced points Approximate the function by Lagrange interpolation polynomial Integration of a simple interpolation polynomial Guassian Quadratures Richardson extrapolation and Romberg integration
8
Basic Numerical Integration Weighted sum of function values x0x0 x1x1 xnxn x n-1 x f(x)f(x)
9
Numerical Integration Idea is to do integral in small parts, like the way you first learned integration - a summation Numerical methods just try to make it faster and more accurate
10
Newton-Cotes formulas - based on idea Approximate f(x) by a polynomial Numerical integration
11
f n (x) can be linear f n (x) can be quadratic
12
f n (x) can also be cubic or other higher-order polynomials
13
Polynomial can be piecewise over the data
14
Numerical Integration Newton-Cotes Closed Formulae -- Use both end points Trapezoidal Rule : Linear Simpson’s 1/3-Rule : Quadratic Simpson’s 3/8-Rule : Cubic Boole’s Rule : Fourth-order* Higher-order methods* Newton-Cotes Open Formulae -- Use only interior points midpoint rule Higher-order methods
15
Closed and Open Formulae (a) End points are known (b) Extrapolation
16
Trapezoidal Rule Straight-line approximation x0x0 x1x1 x f(x)f(x) L(x)
17
Trapezoidal Rule Lagrange interpolation
18
Example:Trapezoidal Rule Evaluate the integral Exact solution Trapezoidal Rule
19
Better Numerical Integration Composite integration Multiple applications of Newton-Cotes formulae Composite Trapezoidal Rule Composite Simpson’s Rule Richardson Extrapolation Romberg integration
20
Apply trapezoidal rule to multiple segments over integration limits Two segments Four segmentsMany segments Three segments
21
Multiple Applications of Trapezoidal Rule
22
Composite Trapezoidal Rule x0x0 x1x1 x f(x)f(x) x2x2 hhx3x3 hhx4x4
23
Trapezoidal Rule Truncation error (single application) Exact if the function is linear ( f = 0) Use multiple applications to reduce the truncation error Approximate error
24
Composite Trapezoidal Rule function f = example1(x) % a = 0, b = pi f=x.^2.*sin(2*x);
25
» a=0; b=pi; dx=(b-a)/100; » x=a:dx:b; y=example1(x); » I=trap('example1',a,b,1) I = -3.7970e-015 » I=trap('example1',a,b,2) I = -1.4239e-015 » I=trap('example1',a,b,4) I = -3.8758 » I=trap('example1',a,b,8) I = -4.6785 » I=trap('example1',a,b,16) I = -4.8712 » I=trap('example1',a,b,32) I = -4.9189 Composite Trapezoidal Rule » I=trap('example1',a,b,64) I = -4.9308 » I=trap('example1',a,b,128) I = -4.9338 » I=trap('example1',a,b,256) I = -4.9346 » I=trap('example1',a,b,512) I = -4.9347 » I=trap('example1',a,b,1024) I = -4.9348 » Q=quad8('example1',a,b) Q = -4.9348 MATLAB function
26
n = 2 I = -1.4239 e-15 Exact = -4. 9348
27
n = 4 I = -3.8758 Exact = -4. 9348
28
n = 8 I = -4.6785 Exact = -4. 9348
29
n = 16 I = -4.8712 Exact = -4. 9348
30
Composite Trapezoidal Rule Evaluate the integral
31
Composite Trapezoidal Rule » x=0:0.04:4; y=example2(x); » x1=0:4:4; y1=example2(x1); » x2=0:2:4; y2=example2(x2); » x3=0:1:4; y3=example2(x3); » x4=0:0.5:4; y4=example2(x4); » H=plot(x,y,x1,y1,'g-*',x2,y2,'r-s',x3,y3,'c-o',x4,y4,'m-d'); » set(H,'LineWidth',3,'MarkerSize',12); » xlabel('x'); ylabel('y'); title('f(x) = x exp(2x)'); » I=trap('example2',0,4,1) I = 2.3848e+004 » I=trap('example2',0,4,2) I = 1.2142e+004 » I=trap('example2',0,4,4) I = 7.2888e+003 » I=trap('example2',0,4,8) I = 5.7648e+003 » I=trap('example2',0,4,16) I = 5.3559e+003
32
Composite Trapezoidal Rule
33
Simpson’s 1/3-Rule Approximate the function by a parabola x0x0 x1x1 x f(x)f(x) x2x2 hh L(x)L(x)
34
Simpson’s 1/3-Rule
36
Composite Simpson’s Rule x0x0 x2x2 x f(x)f(x) x4x4 hhx n-2 hxnxn …... Piecewise Quadratic approximations hx3x3 x1x1 x n-1
37
Composite Simpson’s 1/3 Rule Applicable only if the number of segments is even
38
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)
39
Simpson’s 1/3 Rule Truncation error (single application) Exact up to cubic polynomial ( f (4) = 0) Approximate error for (n/2) multiple applications
40
Composite Simpson’s 1/3 Rule Evaluate the integral n = 2, h = 2 n = 4, h = 1
41
Simpson’s 3/8-Rule Approximate by a cubic polynomial x0x0 x1x1 x f(x) x2x2 hh L(x) x3x3 h
42
Simpson’s 3/8-Rule Truncation error
43
Example: Simpson’s Rules Evaluate the integral Simpson’s 1/3-Rule Simpson’s 3/8-Rule
44
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
45
Simpson’s 1/3 Rule Simpson’s 1/3 Rule
46
Composite Simpson’s 1/3 Rule
47
» 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
48
Multiple applications of Simpson’s rule with odd number of intervals Hybrid Simpson’s 1/3 & 3/8 rules
49
Newton-Cotes Closed Integration Formulae
50
Composite Trapezoidal Rule with Unequal Segments Evaluate the integral h 1 = 2, h 2 = 1, h 3 = 0.5, h 4 = 0.5
51
Trapezoidal Rule for Unequally Spaced Data
52
MATLAB Function: 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)
53
Integral of Unevenly-Spaced Data Trapezoidal rule Could also be evaluated with Simpson’s rule for higher accuracy
54
Composite Simpson’s Rule with Unequal Segments Evaluate the integral h 1 = 1.5, h 2 = 0.5
55
Newton-Cotes Open Formula Midpoint Rule (One-point) ab x f(x) xmxm
56
Two-point Newton-Cotes Open Formula Approximate by a straight line x0x0 x1x1 x f(x)f(x) x2x2 hhx3x3 h
57
Three-point Newton-Cotes Open Formula Approximate by a parabola x0x0 x1x1 x f(x)f(x) x2x2 hhx3x3 hhx4x4
58
Newton-Cotes Open Integration Formulae
59
Area under the function surface Double Integral
60
T(x, y) = 2xy + 2x – x 2 – 2y 2 + 40 Two-segment trapezoidal rule Exact if using single-segment Simpson’s 1/3 rule (because the function is quadratic in x and y) Double Integral
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.