Professional Documents
Culture Documents
Numerical Differential and Integration
Numerical Differential and Integration
Chapter 21
1
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
• Calculus is the mathematics of change. Since engineers continuously deal with
systems and processes that change, calculus is an essential tool of engineering.
• Standing at the heart of calculus are the concepts of:
Differentiation
and Integration
y f ( xi x) f ( xi ) b
I f ( x)dx
x x a
dy f ( xi x) f ( xi )
lim
dx x 0 x
2
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Newton-Cotes Integration Formulas
b b
• Based on the strategy of replacing a
I f ( x)dx f n ( x)dx
complicated function or tabulated data
a a
with an approximating function that is
easy to integrate: f n ( x) a0 a1 x an x n
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The Trapezoidal Rule
• Use a first order polynomial in
approximating the function f(x) :
b b
I f ( x)dx f1 ( x)dx
a a
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 21.1 Single Application of the Trapezoidal Rule
f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5
Integrate f(x) from a=0 to b=0.8
b 0.8
True integral value : I f ( x )dx 1.64053
a 0
1.64053 0.1728
t 89.5%
1.64053
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The Multiple-Application Trapezoidal Rule
• The accuracy can be improved by dividing the
interval from a to b into a number of segments
and applying the method to each segment.
f ( x0 ) f ( x1 ) f ( x1 ) f ( x 2 ) f ( x n1 ) f ( x n )
I h h h
2 2 2
ba n 1
I f ( x 0 ) f ( x n ) 2 f ( x i )
2n i 1 6
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The Error Estimate for
The Multiple-Application Trapezoidal Rule
• Error estimate for one segment is given as:
(b a)3
Et f ( )
12
• An error for multiple-application trapezoidal rule can be obtained by
summing the individual errors for each segment:
h3 n "
Ea f (i ) since f "
( i ) nf "
12 i 1
h3 "
Ea nf where f " is the mean of the second derivative over the interval
12
(b a) (b a)3 " (b a) 2 "
Since h Ea 2
f h f O(h 2
)
n 12n 12
Thus, if the number of segments is doubled,
the truncation error will be quartered.
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Simpson’s Rules
• More accurate estimate of an integral is obtained if
a high-order polynomial is used to connect the
points. These formulas are called Simpson’s rules.
Using a x0 b x2
x2
( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 )
I f ( x0 ) f ( x1 ) f ( x2 )dx
x0
( x0 x1 )( x0 x 2 ) ( x1 x0 )( x1 x 2 ) ( x 2 x0 )( x 2 x1 )
after integratio n and algebraic manipulation, the following formula results :
h ba
I f ( x0 ) 4 f ( x1 ) f ( x2 ) h SIMPSON' S 1/3 RULE
3 2
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The Multiple-Application Simpson’s 1/3 Rule
• Just as the trapezoidal rule, Simpson’s rule can be improved by dividing the integration interval
into a number of segments of equal width.
• However, it is limited to cases where values are equispaced, there are an even number of
segments and odd number of points.
ba
h n # of seg. a x0 b xn
n
x2 x4 xn
I
x0
f 0 ( x)dx f 2 ( x)dx ...
x2
xn2
f ( n 2 ) ( x)dx
h
I ( f ( x0 ) 4 f ( x1 ) f ( x2 ))
3
h
( f ( x2 ) 4 f ( x3 ) f ( x4 ))
3
h
...... ( f ( xn 2 ) 4 f ( xn 1 ) f ( xn ))
3
h n 1 n2
I f ( x0 ) 4 f ( xi ) 2 f ( x j ) f ( xn )
3 i 1, 3, 5... j 2 , 4 , 6...
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Simpson’s 3/8 Rule
Simpson’s 1/3 and 3/8 rules can be
Fit a 3rd order Lagrange interpolating applied in tandem to handle multiple
polynomial to four points and integrate applications with odd number of
intervals
b b
I f ( x)dx f 3 ( x)dx
a a
3h
I f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 )
8
(b a )
h
3
f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 )
I (b a)
8 10
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Newton-Cotes Closed Integration Formulas
Same order,
but Simpson’s 3/8 is more accurate
In engineering practice, higher order (greater than 4-point) formulas are rarely used
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Integration with Unequal Segments
Using Trapezoidal Rule
f ( x0 ) f ( x1 ) f ( x1 ) f ( x2 ) f ( xn 1 ) f ( xn )
I h1 h2 hn
2 2 2
Example 21.7
1.309 0.2 1.305 1.309 0.363 3.181 0.232 2.363
I 0.12 0.10 0.06 0.10
2 2 2 2
0.0905 0.1307 0.12975 1.594
which represents a relative error of = 2.8%
x f(x) x f(x)
0.0 0.2 0.44 2.842
0.40 2.456 12
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Compute Integrals Using MATLAB
First, create a file called fx.m which contains f(x):
x f(x) x f(x)
function y = fx(x)
0.0 0.2 0.44 2.842 y = 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5 ;
0.12 1.309 0.54 3.507
0.22 1.305 0.64 3.181 Then, execute in the command window:
>> Q=integral('fx', 0, 0.8) % true integral
0.32 1.743 0.70 2.363
Or
0.36 2.074 0.80 0.232
>> Q=quad('fx', 0, 0.8) % true integral
0.40 2.456
Q =1.6405 true value
>> x=[0 .12 .22 .32 .36 .4 .44 .54 .64 .7 .8]
>> y = fx(x)
y = 0.200 1.309 1.305 1.743 2.074 2.456
2.843 3.507 3.181 2.363 0.232
Demo: (how I changes wrt n) + (0th order approx. With large n).
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.