0% found this document useful (0 votes)
13 views

Lecture15 - Integracion

The document discusses numerical integration formulas called Newton-Cotes formulas. These formulas approximate integrals using polynomial interpolation over subintervals of the domain. Specific formulas covered include the trapezoidal rule, Simpson's 1/3 rule, and composite versions of these rules. Sources of error in the approximations are also analyzed.

Uploaded by

cmfaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture15 - Integracion

The document discusses numerical integration formulas called Newton-Cotes formulas. These formulas approximate integrals using polynomial interpolation over subintervals of the domain. Specific formulas covered include the trapezoidal rule, Simpson's 1/3 rule, and composite versions of these rules. Sources of error in the approximations are also analyzed.

Uploaded by

cmfaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Part 5

Chapter 17

Numerical Integration
Formulas

Prof. Hae
Hae--Jin Choi

[email protected]

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 1
Chapter Objectives
l Recognizing that Newton-Cotes integration formulas are based on the
strategy of replacing a complicated function or tabulated data with a
polynomial that is easy to integrate.
l Knowing how to implement the following single application Newton-
Cotes formulas:
§ Trapezoidal rule
§ Simpson’s 1/3 rule
§ Simpson’s 3/8 rule
l Knowing how to implement the following composite Newton-Cotes
formulas:
§ Trapezoidal rule
§ Simpson’s 3/8 rule
l Recognizing that even-segment-odd-point formulas like Simpson’s 1/3
rule achieve higher than expected accuracy.
l Knowing how to use the trapezoidal rule to integrate unequally spaced
data.
l Understanding the difference between open and closed integration
formulas. School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 2
Integration
l Integration: b
I= ò f (x) dx
a
is the total value, or summation, of f(x) dx over the range from a to b:
l I represents the area under the curve f(x) between x= a and b.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 3
Integration in Engineering and Science
l This integral can be evaluated over a line, an area, or a volume.
l For example the total mass of gas contained in a volume is given as
the product of the density and the volume. However, suppose that
the density varies from location to location within a volume, it is
necessary to sum the product
n
mass = å ri DVi
i =1

l For a continuous case, the integration is expressed by

mass = òòò r ( x, y, z )dxdydz mass = òòò r (V )dV


V

l There is strong analogy between summation and integration


à Basis of numerical integration

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 4
Newton--Cotes Formulas
Newton
l The Newton-Cotes formulas are the most common numerical
integration schemes.
l Generally, they are based on replacing a complicated function
or tabulated data with a polynomial that is easy to integrate:
b b
I= ò f (x) dx @ ò f (x) dx
a a n

where fn(x) is an nth order interpolating polynomial.


f n ( x) = a0 + a1 x + L + a n -1 x n -1 + a n x n

First-order Parabola
polynomial
(line)

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 5
The Trapezoidal Rule

l The integral can be


approximated using a series of
polynomials applied piecewise
to the function or data over
segments of constant length.
l For example, three straight line
segments are used to
approximate the integral.
Higher-order polynomial can be
used for the same purpose.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 6
The Trapezoidal Rule
l The trapezoidal rule is the first
of the Newton-Cotes closed
integration formulas; it uses a
straight-line approximation for
the function:
b
I = ò f n ( x ) dx
a

é
b f (b) - f ( a ) ù
I = ò ê f (a) + ( x - a )ú dx
a
ë b-a û
f ( a ) + f (b)
I = (b - a ) ® I = (b - a )(average height)
2

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 7
Error of the Trapezoidal Rule
l An estimate for the local truncation
error of a single application of the
trapezoidal rule is:
1 3
Et = - f ¢¢(x )(b - a)
12
where x is somewhere between a
and b.

� l This formula indicates that the error


is dependent upon the curvature of
the actual function as well as the
distance between the points.
l Error can thus be reduced by
breaking the curve into parts.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 8
Example 17.1 (1/2)
l Q. Use the trapezoidal rule to numerically integrate the following
equation from a = 0 to b = 0.8. The true solution is 1.640533.

f ( x) = 0.2 + 2.5 x - 200 x 2 + 675 x 3 - 900 x 4 + 400 x 5

0.2 + 0.232
Sol.) I = (0.8 - 0) = 0.1728
2
® Et = 1.640533 – 0.1728 = 1.467733
® et = 89.5%

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 9
Example 17.1 (2/2)
Approximate error:
f ¢¢( x) = -400 + 4,050 x - 10,800 x 2 + 8,000 x 3
0.8
ò0 (-400 + 4,050 x - 10,800 x 2 + 8,000 x 3 )dx
f ¢¢( x) = = -60
0.8 - 0
1
E a = - (-60)(0.8) 3 = 2.56
12

note : this value is of the same order of magnitude and sign as


the true error. Average second derivative is not an
accurate approximation of f’’(ξ), so a discrepancy exists
and Ea rather Et.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 10
Composite Trapezoidal Rule
l One way to improve the accuracy is to divide
the integration interval from a to b into a
number of segments and apply the method to
each segment.
l Assuming n+1 data points are evenly spaced,
there will be n intervals over which to
integrate. n

(b - a ) 3 n
å f ¢¢(ξ ) i
l The total integral can be calculated by Et = - å f ¢¢(ξ )
i f ¢¢ @ i =1
12n 3 i =1 n
integrating each subinterval and then adding
them together: n
(b - a )3
å f ¢¢(ξ i ) @ nf ¢¢ Ea = -
12n 2
f ¢¢
xn x1 x2 xn i =1
I = ò f n ( x ) dx = ò f n ( x ) dx + ò f n ( x ) dx + L + ò f n ( x ) dx
x0 x0 x1 xn-1

f ( x0 ) + f ( x1 ) f ( x1 ) + f ( x2 ) f ( xn -1 ) + f ( xn ) If the number of
I = ( x1 - x0 ) + ( x2 - x1 ) + L + ( xn - xn -1 )
2 2 2 segments is doubled,
n -1
f ( x0 ) + 2å f ( xi ) + f ( xn ) the error will be
n -1
hé ù quartered
I = ê f ( x0 ) + 2å f ( xi ) + f ( xn ) ú ® I = (b - a) i =1
2ë 1 2 3 2n
û Width 14444244443
i =1
Average height

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 11
MATLAB Program

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 12
Example 17.2 (1/2)
l Q. Use the two-segment and composite trapezoidal rule to estimate
the integral of the function from a = 0 to b = 0.8. The exact value is
1.640533.
f ( x) = 0.2 + 2.5 x - 200 x 2 + 675 x 3 - 900 x 4 + 400 x 5

Sol.
For n = 2 (h = 0.4)
f (0) = 0.2 f (0.4) = 2.456 f (0.8) = 0.232
0.2 + 2(2.456) + 0.232
I = 0.8 = 1.0688
4
E t = 1.640533 - 1.0688 = 0.57173 ε t = 34.9%
0.8 2
Ea = - 2
(-60) = 0.64
12(2)
School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 13
Example 17.2 (2/2)
<Results for the composite trapezoidal rule to estimate the
integral of f(x) = 0.2 + 25x – 200x2 + 675x3 – 900x4
from x = 0 to 0.8. The exact value is 1.640533>
à As the number of segments increases, the error decreases.

n h I et (%)
2 0.4 1.0688 34.9
3 0.2667 1.3695 16.5
4 0.2 1.4848 9.5
5 0.16 1.5399 6.1
6 0.1333 1.5703 4.3
7 0.1143 1.5887 3.2
8 0.1 1.6008 2.4
9 0.0889 1.6091 1.9
10 0.08 1.6150 1.6
School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 14
Simpson’s Rules
l One drawback of the trapezoidal rule is that the error is related to the
second derivative of the function.
l More complicated approximation formulas can improve the accuracy for
curves - these include using (a) 2nd and (b) 3rd order polynomials.
l The formulas that result from taking the integrals under these
polynomials are called Simpson’s rules.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 15
Simpson’s 1/3 Rule
l Simpson’s 1/3 rule corresponds to using second-order
polynomials. Using the Lagrange form for a quadratic fit of three
points:

fn (x) =
(x - x1 ) (x - x2 ) f x + (x - x0 ) (x - x2 ) f x + (x - x0 ) (x - x1 ) f x
( ) ( ) ( )
(x0 - x1 ) (x0 - x2 ) 0 (x1 - x0 ) (x1 - x2 ) 1 (x2 - x0 ) (x2 - x1 ) 2
l Integration over the three points simplifies to:
x2
� I = ò f n ( x ) dx
x0

h f ( x0 ) + 4 f ( x1 ) + f ( x2 )
I= éë f ( x0 ) + 4 f ( x1 ) + f ( x2 ) ùû = I = (b - a )
3 6

Where, h = (b – a)/2, a = x0, b = x2, and x1 = (a + b)/2

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 16
Error of Simpson’s 1/3 Rule
l An estimate for the local truncation error of a single application of
Simpson’s 1/3 rule is:
1 5
Et = - f (4 ) (x )(b - a)
2880
where again x is somewhere between a and b.
l This formula indicates that the error is dependent upon the fourth-
� of the actual function as well as the distance between
derivative
the points.
l Note that the error is dependent on the fifth power of the step size
(rather than the third for the trapezoidal rule).
l Error can thus be reduced by breaking the curve into parts.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 17
Example 17.3
l Q. Use Simpson 1/3 rule to integrate the following equation
from a = 0 to b = 0.8. Exact solution is 1.640533.
f ( x) = 0.2 + 2.5 x - 200 x 2 + 675 x 3 - 900 x 4 + 400 x 5
sol) for n = 2 (h = 0.4)에 대해서
f (0) = 0.2 f (0.4) = 2.456 f (0.8) = 0.232
0.2 + 4(2.456) + 0.232
I = 0.8 = 1.367467
6

® This shows improved results compared to the trapezoidal rule.

Et = 1.640533 - 1.367467 = 0.2730667 εt = 16.6%


0.85
Ea = - (-2400) = 0.2730667
2880
School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 18
Composite Simpson’s 1/3 Rule
l For improved results, Simpson’s
1/3 rule can be used on a set of
subintervals in much the same
way the trapezoidal rule was,
except there must be an odd
number of points..
l Because of the heavy weighting of
the internal points, the formula is a
little more complicated than for the
trapezoidal rule:
xn x2 x4 xn
I= ò x0
fn (x) dx = ò x0
fn (x ) dx + ò x2
fn (x ) dx +L+ ò x n-2
fn (x) dx
h h h
I=
3
[ f (x0 ) + 4 f (x1 ) + f (x2 )]+ [ f (x2 ) + 4 f (x3 ) + f (x4 )]+L+ [ f (xn-2 ) + 4 f (xn-1 ) + f (xn )]
3 3
é ù (b - a )5 ( 4)
n-1 n-2

I = ê f (x0 ) + 4 å f (xi ) + 2 å f (xi ) + f (xn )ú
ú Ea = - 4
f
3 180n
i=1 j=2
êë i, odd j, even úû School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 19
Example 17.4
l Q. Use composite Simpson 1/3 rule to integrate the following
equation from a = 0 to b = 0.8. Exact solution is 1.640533.
f ( x) = 0.2 + 2.5 x - 200 x 2 + 675 x 3 - 900 x 4 + 400 x 5
Sol.) for n = 4 (h = 0.2)
f (0) = 0.2 f (0.2) = 1.288
f (0.4) = 2.456 f (0.6) = 3.464
f (0.8) = 0.232
0.2 + 4(1.288 + 3.464) + 2(2.456) + 0.232
I = 0.8 = 1.623467
12
Et = 1.640533 - 1.623467 = 0.017067 εt = 1.04%

0.85
Estimated error: Ea = - 4
(-2400) = 0.017067
180(4)
School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 20
Example 17.4
l The composite version of Simpson 1/3 rule is superior to
the trapezoidal rule for most applications.
l It is limited to cases where the values are equispaced.,
even number of segments, and odd number of points.
l Odd segment and even point formula is known as
Simpson 3/8 formula.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 21
Simpson’s 3/8 Rule
l Simpson’s 3/8 rule corresponds to
using third-order polynomials to fit
four points. Integration over the
four points simplifies to:
x3
I= ò x0
fn (x) dx
3h
I=
8
[ f (x0 ) + 3 f (x1 ) + 3 f (x2 ) + f (x3 )]

l Simpson’s 3/8 rule is generally


� used in concert with Simpson’s 1/3
rule when the number of segments
is odd.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 22
Higher--Order Formulas
Higher
l Higher-order Newton-Cotes formulas may also be used
- in general, the higher the order of the polynomial used, the
higher the derivative of the function in the error estimate and the
higher the power of the step size.

l As in Simpson’s 1/3 and 3/8 rule, the even-segment-odd-point


formulas have truncation errors that are the same order as
formulas adding one more point. For this reason, the even-
segment-odd-point formulas are usually the methods of
preference.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 23
Example 17.5 (1/2)
l Q. (a) Use Simpson 3/8 to integrate from a = 0 to b = 0.8.
(b) Use it in conjunction with Simpson 1/3 for five segment
integration.
f ( x) = 0.2 + 2.5 x - 200 x 2 + 675 x 3 - 900 x 4 + 400 x 5
Sol.) (a) For n = 3 (h = 0.2667)
f (0) = 0.2 f (0.2667) = 1.432724
f (0.5333) = 3.487177 f (0.8) = 0.232
0.2 + 3(1.432724 + 3.487177) + 0.232
I = 0.8 = 1.51970
8
(b) For n = 5 (h = 0.16)
f (0) = 0.2 f (0.16) = 1.296919
f (0.32) = 1.743393 f (0.48) = 3.186015
f (0.64) = 3.181929 f (0.80) = 0.232
School of Mechanical Engineering
Chung-Ang University
Numerical Methods 2010-2 24
Example 17.5 (2/2)
The integral for the first two segments using Simpson 1/3

0.2 + 4(1.296919) + 1.743393


I = 0.32 = 0.3803237
6
For the last three segments, the Simpson 3/8

1.743393 + 3(3.186015 + 3.181929) + 0.232


I = 0.48 = 1.264754
8

The total integral is by summing the two results.

I = 0.3803237 + 1.264754 = 1.645077

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 25
Summary
<Newton-Cotes integration: h = (b – a)/n>

poi
n name 공 식 절단오차
nts
Trapezoidal f ( x 0 ) + f ( x1 )
1 2 (b - a) - (1 / 12 )h 3 f ¢¢(x)
rull 2

f ( x0 ) + 4 f ( x1 ) + f ( x 2 ) - (1 / 90 )h 5 f ( 4)
( x)
2 3 Simpson 1/3 (b - a)
6

f ( x0 ) + 3 f ( x1 ) + 3 f ( x 2 ) + f ( x3 ) - (3 / 80 )h 5 f ( 4)
(x)
3 4 Simpson 3/8 (b - a)
8
7 f ( x0 ) + 32 f ( x1 ) + 12 f ( x2 ) + 32 f ( x3 ) + 7 f ( x4 )
4 5 Boole’s rull (b - a) - (8 / 945)h 7 f (6)
(x)
90
19 f ( x0 ) + 75 f ( x1 ) + 50 f ( x2 ) + 50 f ( x3 ) + 75 f ( x4 ) + 19 f ( x5 )
5 6 (b - a) - (275 / 12,096 )h 7 f ( 6 ) (x)
288

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 26
Integration with Unequal Segments
l Previous formulas were simplified based on
equispaced data points
- though this is not always the case.
l The trapezoidal rule may be used with data containing
unequal segments:

xn x1 x2 xn
I= ò x0
fn (x) dx = ò x0
fn (x ) dx + ò x1
fn (x ) dx +L+ ò x n-1
fn (x) dx
f (x0 ) + f (x1 ) f (x1 ) + f (x2 ) f (xn-1 ) + f (xn )
I = (x1 - x0 ) + (x2 - x1 ) +L+ (xn - xn-1 )
2 2 2

� School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 27
Integration Code for Unequal
Segments

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 28
MATLAB Functions (option)
l MATLAB has built-in functions to evaluate integrals
based on the trapezoidal rule
l z = trapz(y)
z = trapz(x, y)
produces the integral of y with respect to x. If x is
omitted, the program assumes h=1.

>> x = [0 .12 .22 .32 .36 .4 .44 .54 .64 .7 .8];


>> y = 0.2 + 25*x - 200*x.^2 + 675*x.^3 - 900*x.^4 + 400*x.^5;
>> trapz(x,y)
ans =
1.5948

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 29
Multiple Integrals
• Multiple integrals can be
determined numerically by first
integrating in one dimension,
then a second, and so on for
all dimensions of the problem.

School of Mechanical Engineering


Chung-Ang University
Numerical Methods 2010-2 30

You might also like