Anda di halaman 1dari 46

ENGR 3202

Engineering Analysis and Computation

Integration and Differentiation

Dr. Mohamed Badran

Mechanical Engineering Department

ENGR 3202 Dr. Mohamed Badran Spring 2014


References
• Chapra, Steven C., and Canale, Raymond P.
“Numerical Methods for Engineers”, 5th edition,
McGraw Hill. Inc., 2006.

ENGR 3202 Dr. Mohamed Badran Spring 2014


Newton-Cotes Integration Formulas
Using these formulas, the complication function is replaced with
some approximating function that is easy to integrate:
𝑏 𝑏
𝐼= 𝑓 𝑥 𝑑𝑥 ≈ 𝑓𝑛 𝑥 𝑑𝑥
𝑎 𝑎

where fn(x) is a polynomial of the form:


𝑓𝑛 𝑥 = 𝑎0 + 𝑎1 𝑥 + ⋯ + 𝑎𝑛−1 𝑥 𝑛−1 + 𝑎𝑛 𝑥 𝑛

ENGR 3202 Dr. Mohamed Badran Spring 2014


Single versus series of polynomials
The integral can be approximated by a single polynomial or a
series of polynomials applied piece-wise

Single polynomial Series of polynomials applied piece-wise

ENGR 3202 Dr. Mohamed Badran Spring 2014


Closed versus Open Form
Closed form Newton Cotes formulas:

Those where the integration domain is


bounded by 2 data points.

Open form Newton Cotes formulas:

The integration domain extends beyond


the range of the data; they are usually not
employed with definite integral

ENGR 3202 Dr. Mohamed Badran Spring 2014


The Trapezoidal Rule
The first of the Newton-Cotes closed integration formulas,
corresponding to the case where the polynomial is first order:
b b
𝑓 𝑏 −𝑓 𝑎
I   f ( x)dx   f1 ( x)dx , where 𝑓1 𝑥 = 𝑓 𝑎 +
𝑏−𝑎
(𝑥 − 𝑎)
a a
𝑏
𝑓 𝑏 −𝑓 𝑎
≈ 𝑓 𝑎 + 𝑥 − 𝑎 𝑑𝑥
𝑎 𝑏−𝑎

𝑓 𝑎 +𝑓 𝑏
≈ 𝑏−𝑎
2

≈ 𝑏 − 𝑎 𝑥 𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑕𝑒𝑖𝑔𝑕𝑡

Error of the trapezoidal rule:


1 "
𝐸𝑡 = − 𝑓 ξ (𝑏 − 𝑎)3 , 𝑎<ξ<𝑏
12
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 1(21.1)*
Use the trapezoidal rule to numerically integrate the following
function from a = 0 to b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 1(21.1)*
continued

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
The Composite Trapezoidal Rule
The integration domain is divided into a number of segments and
the trapezoidal rule is applied to each segment.

ENGR 3202 Dr. Mohamed Badran Spring 2014


The Composite Trapezoidal Rule
continued
𝑏−𝑎
𝑕= , 𝑤𝑕𝑒𝑟𝑒 𝑛 𝑖𝑠 𝑡𝑕𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑒𝑔𝑚𝑒𝑛𝑡𝑠
𝑛
a  x0 b  xn
xn x1 x2 xn

I  f ( x)dx   f ( x)dx   f ( x)dx     f ( x)dx


x0 x0 x1 xn1

Substituting the trapezoidal rule for each


integral yields:
f ( x0 )  f ( x1 ) f ( x1 )  f ( x2 ) f ( xn1 )  f ( xn )
I h h  h
2 2 2
Or, grouping terms

𝑕 𝑛−1 𝑓(𝑥 0 )+2 𝑛𝑖=1


−1
𝑓 𝑥 𝑖 + 𝑓(𝑥 𝑛 )
𝐼= 𝑓(𝑥0 ) + 2 𝑖=1 𝑓 𝑥𝑖 + 𝑓(𝑥𝑛 ) = (𝑏 − 𝑎)
2 2𝑛

ENGR 3202 Dr. Mohamed Badran Spring 2014


The Composite Trapezoidal Rule
continued
The error for the composite trapezoidal rule can be computed by
summing up the individual errors for each segment
𝑛
(𝑏 − 𝑎)3
𝐸𝑡 = − 𝑓 " ξ𝑖
12𝑛3
𝑖=1
𝑛
(𝑏 − 𝑎)3 " " ≅ 𝑖=1 𝑓 "
ξ𝑖
𝐸𝑎 = − 𝑓 , 𝑠𝑖𝑛𝑐𝑒 𝑓
12𝑛2 𝑛

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 2(21.2)*
Use the composite trapezoidal rule employing n= 2,3,4,..,10 to
numerically integrate the following function from a = 0 to
b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 2(21.2)*
continued

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

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
The Simpson’s Rules
Higher order polynomials may be employed to obtain higher
accuracy. The formulas that result from taking the integrals under
these polynomials are called “Simpson’s Rules.”

a. Simpson’s 1/3 Rule


𝑏 𝑏
𝐼= 𝑓 𝑥 𝑑𝑥 ≈ 𝑓2 𝑥 𝑑𝑥
𝑎 𝑎

where f2(x) is a second order


Lagrange polynomial.

a h h b

ENGR 3202 Dr. Mohamed Badran Spring 2014


Simpson’s 1/3 Rule
b b
I   f ( x)dx   f 2 ( x)dx
a a

a  x0 b  x2
 ( x  x1 )( x  x2 ) ( x  x0 )( x  x2 ) ( x  x0 )( x  x1 ) 
x2

I   f ( x0 )  f ( x1 )  f ( x2 )dx
x0 
( x0  x1 )( x0  x2 ) ( x1  x0 )( x1  x2 ) ( x2  x0 )( x2  x1 ) 
ba
I   f ( x0 )  4 f ( x1 )  f ( x2 )
h
h
3 2
Single segment application of Simpson’s 1/3 rule has a
truncation error of:

(b  a)5 ( 4)
Et   f ( ) a  b
2880

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 3(21.4)*
Use the Simpson’s 1/3 rule to numerically integrate the following
function from a = 0 to b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
The Composite Simpson’s Rule
𝑏−𝑎
𝑕= , 𝑤𝑕𝑒𝑟𝑒 𝑛 𝑖𝑠 𝑎𝑛 𝑒𝑣𝑒𝑛 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑒𝑔𝑚𝑒𝑛𝑡𝑠
𝑛
a  x0 b  xn
xn x2 x4 xn

I  f ( x)dx   f ( x)dx   f ( x)dx 


x0 x0 x2
 
xn2
f ( x )dx

Substituting the Simpson’s 1/3 rule for each


integral yields:
f ( x0 )  4 f ( x1 )  f ( x2 ) f ( x2 )  4 f ( x3 )  f ( x4 )
I  2h  2h
6 6
f ( xn  2 )  4 f ( xn 1 )  f ( xn )
...  2h
6
Or, grouping terms
n 1 n2
f ( x0 )  4  f ( xi )  2  f ( x j )  f ( xn )
i 1,3,5 j  2,4,6
I  (b  a)
3n
ENGR 3202 Dr. Mohamed Badran Spring 2014
The Composite Simpson’s 1/3 Rule
continued
The error for the composite Simpson’s 1/3 rule can be computed by
summing up the individual errors for each segment

(𝑏 − 𝑎)5 (4)
𝐸𝑎 = − 4
𝑓
180𝑛

Where f (4) is the average fourth derivative for the interval

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 4(21.5)*
Use Simpson’s 1/3 rule with n=4 to numerically integrate the
following function from a = 0 to b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Simpson’s 3/8 Rule
Fitting a 3rd order Lagrange polynomial to 4 points yields
(b  a)
h
3
b b

 f ( x)dx   f ( x)dx
a a
3

3h
I  f ( x0 )  3 f ( x1 )  3 f ( x2 )  f ( x3 )
8

I  (b  a)
 f ( x0 )  3 f ( x1 )  3 f ( x2 )  f ( x3 )
8
Simpson’s 3/8 rule has a truncation error of:
(b  a)5 (4)
Et   f ( ) a  b h h h
6480 a b

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 5(21.6a)*
Use Simpson’s 3/8 rule to numerically integrate the following
function from a = 0 to b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 6(21.6b)*
Use Simpson’s 3/8 rule in conjunction with Simpson 1/3 rule to
numerically integrate the following function for 5 segments from
a = 0 to b = 0.8:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 6(21.6b)*
continued

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Integration with unequal segments
This often occurs when integrating experimentally derived data.

It is possible to employ the trapezoidal rule for each segment


independently as follows:
f ( x0 )  f ( x1 ) f ( x1 )  f ( x2 ) f ( xn1 )  f ( xn )
I  h1  h2  ...  hn
2 2 2

However higher accuracy is achieved if Simpson’s rules are


employed whenever possible.

Whenever 2 or 3 successive equal segments exist, then employ


Simpson’s 1/3 or 3/8 rule, respectively. Else employ the
trapezoidal rule
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 7(21.7)*
Use the trapezoidal rule to numerically integrate the following
data (which was generated from:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
employing unequal segments) The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 8(21.8)*
Recompute the integral for the data below, but use Simpson’s
rules for those segments where they are appropriate.
Recall, The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 8(21.8)*
continued
Interval 1 2 3
x 0 0.12 0.22 0.32
Interval 0.12 0.1 0.1
Width
Trapezoidal
Simpson’s 1/3

Interval 4 5 6
x 0.32 0.36 0.40 0.44
Interval 0.04 0.04 0.04
Width
Simpson’s 3/8

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 8(21.8)*
continued
Interval 7 8 9 10
x 0.44 0.54 0.64 0.70 0.8
Interval 0.1 0.1 0.06 0.1
Width
Simpson’s 1/3
Trapezoidal
Trapezoidal

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 8(21.8)*
continued

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Multiple Integrals
They are widely used in engineering. A simple example would be
to take the double integral of a function over a rectangular area.
b d
I    f ( x, y )dydx
a c

Recall form calculus that such integrals


can be computed as iterated integrals

b d
 
d b

I     f ( x, y )dy dx     f ( x, y )dx dy
ac  ca 

Thus, the integral in one of the dimensions is evaluated first. The result
integration is integrated in the second dimension.

ENGR 3202 Dr. Mohamed Badran Spring 2014


Multiple Integrals
b
d  
d b

I     f ( x, y )dy dx     f ( x, y )dx dy
ac  ca 

• Double integration is a twice application of a single numerical


integration method, once in the y-direction and one for the x-
direction.
• Any numerical integration method for single integration can be
applied to double integration.
• The same concept may be extended to 3 or more dimensions

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 9(21.9)*
Suppose that the temperature of a rectangular heated plate is
described by the following function:
T ( x, y)  2 xy  2 x  x2  2 y 2  72
If the plate is 8-m long (x-dimension) and 6-m wide (y
dimension), compute the average temperature.
a. Using multiple trapezoidal rule with n=2 in both dimensions.
b. Using single application of Simpson’s 1/3 rule in both
dimensions.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 9(21.9)*
continued

2544

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Integration of Equations
When given an analytic function to integrate, we can generate values at
any point we desire. This can be exploited to yield higher accuracy.
Gauss Quadrature
It can be used to integrate numerically
analytic functions only.

The 2-point quadrature formula employs a


straight line fit similar to the trapezoidal
rule; however, x0 and x1 are chosen so that
the area under the straight line is exactly
equal to the integral of a cubic and simpler
function

ENGR 3202 Dr. Mohamed Badran Spring 2014


Derivation of the Two-point Gauss-
Legendre Formula
I  c0 f ( x0 )  c1 f ( x1 )
To derive c0 , c1 x0 x1
1
c0 f ( x0 )  c1 f ( x1 )   1dx  2
1
1
c0 f ( x0 )  c1 f ( x1 )   xdx  0
1
1
2
c0 f ( x0 )  c1 f ( x1 )   x 2 dx 
1
3
1
c0 f ( x0 )  c1 f ( x1 )   x 3dx  0
1

ENGR 3202 Dr. Mohamed Badran Spring 2014


Derivation of the Two-point Gauss-
Legendre Formula continued
c0  c1  2
c0 x0  c1 x1  0
Solving the equations yields:
1 1
2 c0  c1  1, x0   , x1 
c x c x 
2
0 0
2
1 1
3 3
3
c0 x03  c1 x13  0  1   1 
I  f   f 
 3  3
If the limits of integration are not -1,1 then a new variable xd is defined by:
x  a0  a1 xd
a  a0  a1 (1) ba ba
a0  , a1 
b  a0  a1 (1) 2 2

ba  ba ba


x     xd dx    dxd
 2   2   2 
and the integral is performed for the transformed function
ENGR 3202 Dr. Mohamed Badran Spring 2014
Example 10(22.3)*
Use 2-point Gauss-Legendre formula to evaluate the integral of:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
between x=0 and x=0.8.
Recall, The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Higher-Point Formulas
I  c0 f ( x0 )  c1 f ( x1 )  .....  cn1 f ( xn1 ) , n= number of points

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 11(22.4)*
Use 3-point Gauss-Legendre formula to evaluate the integral of:
𝑓 𝑥 = 0.2 + 25𝑥 − 200 𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
between x=0 and x=0.8.
Recall, The exact solution is 1.64053334.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Numerical Differentiation
We can employ Taylor series expansions to derive finite-divided
difference approximations of derivatives.

We can develop forward, backward and centered difference


approximations of first and higher derivatives.

ENGR 3202 Dr. Mohamed Badran Spring 2014


Higher-accuracy differentiation formulas
From Taylor’s forward series:
f " xi  2 f " ' xi  3
f xi 1   f xi   f ' xi .h  h  h  ... , h  xi 1  xi (1)
2 3!
From (1):
f xi 1   f xi  f " xi  f xi 1   f xi 
f ' ( xi )   h  O h 2    O h  (2)
h 2 h

Writing Taylor’s series for f(xi+2) about f(xi):


f " xi  2 f " ' xi  3 (3)
f xi  2   f xi   f ' xi .2h  .4h  .8h  ...
2 3!

Eliminating f ’(xi) from (1) and (3) yields:


f xi  2   2 f xi 1   f xi  (4)
f " xi    O h 
h2

Equations (2) and (4) are the forward finite divided difference
formulas for f ’(xi) and f”(xi) of O(h)
ENGR 3202 Dr. Mohamed Badran Spring 2014
Forward Finite-Divided Difference

ENGR 3202 Dr. Mohamed Badran Spring 2014


Backward Finite-Divided Difference

ENGR 3202 Dr. Mohamed Badran Spring 2014


Centered Finite-Divided Difference

ENGR 3202 Dr. Mohamed Badran Spring 2014


Example 12(23.1)*
Obtain the derivative of the following function at x=0.5 with
h=0.25
f ( x)  0.1x4  0.15x3  0.5x2  0.25x  1.2
The exact solution is -0.9125. Employ formulas yielding highest
accuracy.

*Chapra, Steven C., and Canale, Raymond P. “Numerical Methods for Engineers”, 5th edition, McGraw Hill. Inc., 2006.
ENGR 3202 Dr. Mohamed Badran Spring 2014
Improving Derivative estimates
1. Decrease h
2. Use a higher-order formula that employs more points
3. C.D. formulas are preferred to F.D. or B.D. Formulas with
the same number of points.

ENGR 3202 Dr. Mohamed Badran Spring 2014

Anda mungkin juga menyukai