Title: Numerical Integration Formulas
1Chapter 17
- Numerical Integration Formulas
2(No Transcript)
3Graphical Representation of Integral
Use of a grid to approximate an integral
Integral area under the curve
4Use of strips to approximate an integral
5Numerical Integration
Net force against a skyscraper
Cross-sectional area and volume flowrate in a
river
Survey of land area of an irregular lot
6Pressure Force on a Dam
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.
p ?gh ?h
7Integration
- 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
8Basic Numerical Integration
- Weighted sum of function values
f(x)
x
x0
x1
xn
xn-1
9Numerical 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
10Numerical integration
Newton-Cotes formulas - based on idea
- Approximate f(x) by a polynomial
11- fn (x) can be linear
- fn (x) can be quadratic
12- fn (x) can also be cubic or other higher-order
polynomials
13- Polynomial can be piecewise over the data
14Numerical Integration
- Newton-Cotes Closed Formulae -- Use both end
points - Trapezoidal Rule Linear
- Simpsons 1/3-Rule Quadratic
- Simpsons 3/8-Rule Cubic
- Booles Rule Fourth-order
- Higher-order methods
- Newton-Cotes Open Formulae -- Use only interior
points - midpoint rule
- Higher-order methods
15Closed and Open Formulae
(a) End points are known (b)
Extrapolation
16Trapezoidal Rule
- Straight-line approximation
f(x)
L(x)
x
x0
x1
17Trapezoidal Rule
18ExampleTrapezoidal Rule
- Evaluate the integral
- Exact solution
- Trapezoidal Rule
19Better Numerical Integration
- Composite integration
- Multiple applications of Newton-Cotes formulae
- Composite Trapezoidal Rule
- Composite Simpsons Rule
- Richardson Extrapolation
- Romberg integration
20Apply trapezoidal rule to multiple segments over
integration limits
Two segments
Three segments
Four segments
Many segments
21Multiple Applications of Trapezoidal Rule
22Composite Trapezoidal Rule
f(x)
x
x0
x1
x2
h
h
x3
h
h
x4
23Trapezoidal Rule
- Truncation error (single application)
- Exact if the function is linear ( f ? 0)
- Use multiple applications to reduce the
truncation error
Approximate error
24Composite Trapezoidal Rule
function f example1(x) a 0, b
pi fx.2.sin(2x)
25Composite Trapezoidal Rule
a0 bpi dx(b-a)/100 xadxb
yexample1(x) Itrap('example1',a,b,1) I
-3.7970e-015 Itrap('example1',a,b,2) I
-1.4239e-015 Itrap('example1',a,b,4) I
-3.8758 Itrap('example1',a,b,8) I
-4.6785 Itrap('example1',a,b,16) I
-4.8712 Itrap('example1',a,b,32) I -4.9189
Itrap('example1',a,b,64) I -4.9308
Itrap('example1',a,b,128) I -4.9338
Itrap('example1',a,b,256) I -4.9346
Itrap('example1',a,b,512) I -4.9347
Itrap('example1',a,b,1024) I -4.9348
Qquad8('example1',a,b) Q -4.9348
MATLAB function
26n 2 I -1.4239 e-15 Exact -4. 9348
27n 4 I -3.8758 Exact -4. 9348
28n 8 I -4.6785 Exact -4. 9348
29n 16 I -4.8712 Exact -4. 9348
30Composite Trapezoidal Rule
31Composite Trapezoidal Rule
x00.044 yexample2(x) x1044
y1example2(x1) x2024 y2example2(x2)
x3014 y3example2(x3) x400.54
y4example2(x4) Hplot(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)') Itrap('example2',0,4,1) I
2.3848e004 Itrap('example2',0,4,2) I
1.2142e004 Itrap('example2',0,4,4) I
7.2888e003 Itrap('example2',0,4,8) I
5.7648e003 Itrap('example2',0,4,16) I
5.3559e003
32Composite Trapezoidal Rule
33Simpsons 1/3-Rule
- Approximate the function by a parabola
L(x)
f(x)
x
x0
x1
x2
h
h
34Simpsons 1/3-Rule
35Simpsons 1/3-Rule
36Composite Simpsons Rule
Piecewise Quadratic approximations
f(x)
...
x
x0
x2
x4
h
h
xn-2
h
xn
h
x3
x1
xn-1
37Composite Simpsons 1/3 Rule
- Applicable only if the number of segments is even
38Composite Simpsons 1/3 Rule
- Applicable only if the number of segments is even
- Substitute Simpsons 1/3 rule for each integral
- For uniform spacing (equal segments)
39Simpsons 1/3 Rule
- Truncation error (single application)
- Exact up to cubic polynomial ( f (4) 0)
- Approximate error for (n/2) multiple applications
40Composite Simpsons 1/3 Rule
- Evaluate the integral
- n 2, h 2
- n 4, h 1
41Simpsons 3/8-Rule
- Approximate by a cubic polynomial
f(x)
L(x)
x
x0
x1
x2
h
h
x3
h
42Simpsons 3/8-Rule
43Example Simpsons Rules
- Evaluate the integral
- Simpsons 1/3-Rule
- Simpsons 3/8-Rule
44Composite Simpsons 1/3 Rule
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 hi S S 4feval(f,
x(i)) end for i 2 2 n-2 x(i) a
hi S S 2feval(f, x(i)) end S S
feval(f, b) I hS/3
45 Simpsons 1/3 Rule
46Composite Simpsons 1/3 Rule
47 x00.044 yexample(x) x1024
y1example(x1) cLagrange_coef(x1,y1)
p1Lagrange_eval(x,x1,c) Hplot(x,y,x1,y1,'r',
x,p1,'r') xlabel('x') ylabel('y')
title('f(x) xexp(2x)') set(H,'LineWidth',3,'
MarkerSize',12) x2014 y2example(x2)
cLagrange_coef(x2,y2) p2Lagrange_eval(x,x2,c)
Hplot(x,y,x2,y2,'r',x,p2,'r') xlabel('x')
ylabel('y') title('f(x) xexp(2x)')
set(H,'LineWidth',3,'MarkerSize',12)
ISimp('example',0,4,2) I 8.2404e003
ISimp('example',0,4,4) I 5.6710e003
ISimp('example',0,4,8) I 5.2568e003
ISimp('example',0,4,16) I 5.2197e003
QQuad8('example',0,4) Q 5.2169e003
n 2 n 4 n 8 n 16
MATLAB fun
48Multiple applications of Simpsons rule with odd
number of intervals
Hybrid Simpsons 1/3 3/8 rules
49Newton-Cotes Closed Integration Formulae
50Composite Trapezoidal Rule with Unequal Segments
- Evaluate the integral
- h1 2, h2 1, h3 0.5, h4 0.5
51Trapezoidal Rule for Unequally Spaced Data
52MATLAB Function trapz
x0 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 yx.exp(2.x) y 1.0e004
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.3651e003
53Integral of Unevenly-Spaced Data
- Trapezoidal rule
- Could also be evaluated with Simpsons rule for
higher accuracy
54Composite Simpsons Rule with Unequal Segments
- Evaluate the integral
- h1 1.5, h2 0.5
55Newton-Cotes Open FormulaMidpoint Rule
(One-point)
f(x)
x
a
b
xm
56Two-point Newton-Cotes Open Formula
- Approximate by a straight line
f(x)
x
x0
x1
x2
h
h
x3
h
57Three-point Newton-Cotes Open Formula
- Approximate by a parabola
f(x)
x
x0
x1
x2
h
h
x3
h
h
x4
58Newton-Cotes Open Integration Formulae
59Double Integral
- Area under the function surface
60Double Integral
- T(x, y) 2xy 2x x2 2y2 40
- Two-segment trapezoidal rule
- Exact if using single-segment Simpsons 1/3 rule
(because the function is quadratic in x and y)