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

Chapter 3 - Numerical Integration and Differentiation

The document discusses numerical integration and differentiation techniques. It introduces the Newton-Cotes integration formulas which approximate integration of functions defined by data tables by replacing them with easy-to-integrate polynomials. The Trapezoidal Rule is presented as one of the Newton-Cotes methods that approximates the area under a curve using trapezoids formed by the function values at the endpoints. Examples are provided to demonstrate calculating integrals numerically using the Trapezoidal Rule and comparing to exact analytical solutions.

Uploaded by

phanmquan2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Chapter 3 - Numerical Integration and Differentiation

The document discusses numerical integration and differentiation techniques. It introduces the Newton-Cotes integration formulas which approximate integration of functions defined by data tables by replacing them with easy-to-integrate polynomials. The Trapezoidal Rule is presented as one of the Newton-Cotes methods that approximates the area under a curve using trapezoids formed by the function values at the endpoints. Examples are provided to demonstrate calculating integrals numerically using the Trapezoidal Rule and comparing to exact analytical solutions.

Uploaded by

phanmquan2004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

CHAPTER 3
NUMERICAL INTEGRATION
AND DIFFERENTIATION
Dr. Le Thanh Long
[email protected]

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

OUTLINE
3.1. Numerical Integration
3.2. Numerical Differentiation
3.3. Lagrange Interpolating Polynomials

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration

Figure 3.1: Examples of how integration is used to evaluate areas in engineering


applications.
(a) Evaluating the area of a field bounded by a meandering stream and two roads.
(b) Evaluating the cross-sectional area of a river.
(c) Determining the net force due to a nonuniform wind blowing against the side of
a skyscraper.
3

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


Newton-Leibnitz Integration Formulas
b b
 f ( x)dx  F ( x)  F (b)  F (a)
a a
where F’(x) = f(x), F is a primitive function of f.

But we have often to determine the integration of the


function y = f(x) defined by the data table. So, the concept
of primitive function makes sense no longer.

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


Newton-Cotes Integration Formulas
• This is the most common numerical integration schemes.
• Base on the strategy of replacing a complicated function
or tabulated data with an approximating function that is
easy to integrate:
b b
I   f ( x)dx   f n ( x)dx
a a
where:

f n ( x)  a0  a1 x  a2 x 2  ...  an x n

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


Example 3.1: Computing the integration by analytical method (Newton-
Leibnitz) and numerical integration method (Newton-Cotes)
1
2
 (96 x  42 x  13) dx
Solution: 1

Let I1 the integration calculated by analytical method (Newton-Leibnitz) và I2


the integration calculated by numerical method (Newton-Cotes)
- Analytical method:
1
2 3 2 1
I1   (96 x  42 x  13) dx  (32 x  21x  13 x )  38
1
1
- Numerical method:
Look up Table 1.1 in Appendix 1, the abscissa of the integral points xi and the
corresponding weights ωi are x1 = -1, ω1 = ; x2 = 0, ω2 = ; x3 = 1, ω3 =
1
1 4 1
I 2   (96 x2  42 x 13)dx  [96(1)2  42(1) 13]  [96(0)2  42(0) 13]  [96(1)2  42(1) 13]
1
3 3 3
41 52 125
    38
3 3 3 5

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
Using first order Taylor series to approximate ,
b b
I   f ( x)dx   f1 ( x)dx
a a

where:
f (b)  f (a )
f1 ( x)  f (a )  ( x  a)
ba
Then:
b f (b)  f (a )  f (b)  f (a)
I    f (a)  ( x  a)   (b  a)
a
 ba  2

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
The trapezoidal rule is
equivalent to approximating
the area of the trapezoidal
under the straight line
connecting ( ) and .
An estimated for the local
truncation error of a single
application of the
trapezoidal rule is:
Figure 3.2: Graphical depiction of 1
(b  a )3 f "( x)
the trapezoidal rule. 12

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
Example 3.2: Use the trapezoidal rule to numerically integrate the function
f(x) = 0.2 + 25x from a = 0 to b = 2
Solution:
2
2
2
The true solution is  f ( x)dx  (0.2  12.5 x )  50.4
0 0
f (a )  f (0)  0.2
f (b)  f (2)  50.2

f (b)  f (a ) 0.2  50.2


I  (b  a )  (2  0)  50.4
2 2
Because ( ) is a linear function, using the trapezoidal rule gets the
exact solution.
8

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
Example 3.3: Use the trapezoidal rule to numerically integrate the function
f(x) = 0.2 + 25x + 3x2 from a = 0 to b = 2
Solution: f (0)  0.2; f (2)  62.2
f (b)  f ( a )
I  (b  a )  62.4
2
The exact solution is
2
2 3 2
 f ( x)dx  (0.2 x  12.5 x  x )  58.4
0 0
The relative error is:
58.4  62.4
t  100%  6.85%
58.4
9

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
Multiple-application trapezoidal rule
Using a smaller integration interval can reduce the approximation
error. Divide [a, b] into n segments of equal width h = .
n 1
f ( x0 )  2 i 1 f ( xi )  f ( xn )
I  (b  a )
2n
Error:
(b  a )3
Ea   2
f "( x)
12n

10

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


1. The Trapezoidal Rule
Example 3.4: Use the 2-segments trapezoidal rule to numerically
integrate and estimate the error of f(x) = 0.2 + 25x + 3x2 from a = 0 to b = 2
Solution: (b  a)
n  2; h  1
n
f (0)  0.2; f (1)  28.2; f (2)  62.2
f (0)  2 f (1)  f (2)
I  (b  a)  59.4
2n
Error: 2
 6dx
0
f "( x)  6, f "( x)  6
3
20
(2  0)
Ea   2
6  1
12x2
The exact solution is 59.4 – 1 = 58.4 The relative error is 1.71%
11

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


2. Simpson’s Rule
Aside from applying the trapezoidal rule with finer segmentation,
another way to improve the estimation accuracy is to use higher-
order polynomials.
Multiple-application Simpson’s rule:
b m m 1
h 
 f ( x)dx   f 0  f 2 m  4 f 2 k 1  2 f 2 k 
a
3 k 1 k 1 
(b  a )5 (4)
Error: Ea   4
f
180n

Where ̅( ) is the average fourth derivative for the interval.


13

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


2. Simpson’s Rule
Example 3.5: With n = 4, estimate the integral and error of
= 0.2 + 25 − 200 + 675 − 900 + 400
From a = 0 to b = 0.8. The exact integral is 1.640533
Solution: h = 0.2
f(0) 0.2 0.2
I  0.2  4(1.288  3.464)  2(2.456)  0.232  1.623467
3
f(0.2) 1.288
f(0.4) 2.456 = 1.640533 − 1.623467 = 0.017067
f(0.6) 3.464 = 1.04%
f(0.8) 0.232 0.85
The estimated error is Ea  4
(2400)  0.017067
180(4)

14

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.1. Numerical Integration


2. Simpson’s Rule
Example 3.6: Use Simpson’s rule to estimate the integral and error
of 0 1 dx with the number of segments n = 6
0.6

1 x
0, 6  0
Solution: h  0,1
6
0.1
x y I { f (0)  f (0.6)  4[ f (0.1)  f (0.3)  f (0.5)]
3
0 (0) = 1  2[ f (0.2)  f (0.4)]}  0.470
0.1 (0.1) = 0.909 0.6 24
0.2 (0.2) = 0.833 24 0 (1  x)5 dx
f ""( x)  5
; f ""( x)   8.47
(1  x) 0.6  0
0.3 (0.3) = 0.769
0.4 (0.4) = 0.714 0.65
Ea   4
8.47  0.000003
180  6
0.5 (0.5) = 0.667
0.6 (0.6) = 0.625 => True integral ≈ 0.469997
15

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem 1. Evaluate the following integral:


 /2

 (6  3cos x)dx
0

a) Multiple-application trapezoidal rule, with n = 4.

b) Multiple-application Simpson’s rule, with n = 4.

c) Determine the percent relative error of the two methods above.

16

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem 1.
Solution:
a) Multiple-application trapezoidal rule

−0
ℎ=2 = /8
4

= 0; = /8; = /4; = 3 /8; = /2

 f (0)  f ( / 2)  2[ f ( / 8)  f ( / 4)  f (3 / 8)]


I
8 2
  3 
 [9  6  2[18  3cos  3cos  3cos ]
16 8 4 8
 12.386
17

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem 1.
Solution:
b) Multiple-application Simpson’s rule
−0
ℎ=2 = /8
4
= 0; = /8; = /4; = 3 /8; = /2

 f (0)  4[ f ( / 8)  f (3 / 8)]  2 f ( / 4)  f ( / 2)


I
8 3

 [9  4(12  3cos( / 8)  3cos(3 / 8))  2(6  3cos( / 4))  6]  12.4252
24

18

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem 1.
Solution:
c) Determine the percent relative error
 /2  /2  /2

 (6  3cos x)dx  6  dx  3  cos xdx


0 0 0

 3  3  12.42478
Multiple-application trapezoidal rule
12.386  12.42478
T  100%  0.312%
12.42478
Multiple-application Simpson’s rule

12.4252  12.42478
T  100%  0.003%
12.42478
19

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


1. First Order Derivatives

Figure 3.3: Graphical depiction of forward, backward and centered


finite-divided-difference approximations of the first derivative. 20

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


1. First Order Derivatives
The first forward finite divided difference is
f ( xi 1 )  f ( xi )
f '( xi ) 
h
The first backward finite divided difference is
f ( xi )  f ( xi 1 )
f '( xi ) 
h
The first centered finite divided difference is
f ( xi 1 )  f ( xi 1 )
f '( xi ) 
2h
In case that we consider 4 points
 f  x0  2h   8 f  x0  h   8 f  x0  h   f  x0  2h 
f   x0  
12h 21

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


Example 3.7: Estimate the first order derivative of f(x) at x = 0.5 and
h = 0.5
f ( x)  0.1x 4  0.15 x 3  0.5 x 2  0.25 x  1.2
Solution:
 xi  0.5  f ( xi )  0.925
 
 xi 1  xi  h  0   f ( xi 1 )  1.2
x  x  h  1  f ( x )  0.2
 i 1 i  i 1

The first forward divided difference:


f ( xi 1 )  f ( xi )
f '( xi )   1.45
h
The first backward divided difference:
f ( xi )  f ( xi 1 )
f '( xi )   0.55
h 22

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


Example 3.7
Solution:
The first centered divided difference:
f ( xi 1 )  f ( xi 1 )
f '( xi )   1.0
2h

Exact differentiate: -0.9125

=> Using centered finite divided difference and small step size
achieves lower approximation error

23

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


2. Second Order Derivatives
The second forward finite divided difference is
f ( xi  2 )  2 f ( xi 1 )  f ( xi )
f "( xi ) 
h2
The second backward finite divided difference is
f ( xi )  2 f ( xi 1 )  f ( xi  2 )
f "( xi ) 
h2
The second centered finite divided difference is
f ( xi 1 )  2 f ( xi )  f ( xi 1 )
f "( xi ) 
h2
In case that we consider 5 points
 f  x0  2h   16 f  x0  h   30 f  x0   16 f  x0  h   f  x0  2h 
f   x0  
12h 2 24

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.2. Numerical Differentiation


2. Second Order Derivatives
Example 3.8: Evaluate the second derivatives of function f(x) at x = 0.5
and h = 0.25
f ( x)  0.1x 4  0.15 x3  0.5 x 2  0.25 x  1.2
Solution:
 xi  0.5  f ( xi )  0.925
 x  0.25  f ( x )  1.1035 Using the forward f.d.d: f "( xi )  2.326
 i 1  i 1

 xi  2  0   f ( xi  2 )  1.2 Using the backward f.d.d: f "( xi )  1.312


 x  0.75  f ( x )  0.6363
 i 1  i 1 Using the centered f.d.d: f "( xi )  1.7632
 xi  2  1  f ( xi  2 )  0.2
Exact differentiate: -1.75

25

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem 2. Use the following data to find the velocity and


acceleration at t = 10 seconds. Use centered finite difference.

Time, t, s 0 2 4 6 8 10 12 14 16
Position, x, m 0 0.7 1.8 3.4 5.1 6.3 7.3 8.0 8.4

26

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Solution:

• Velocity: f ( xi 1 )  f ( xi 1 )
f '( xi ) 
2h

f ( x6 )  f ( x4 )
f '( x5 ) 
2h
f (12)  f (8) 7.3  5.1
f '(10)    0.55(m / s )
2 2 2 2
• Acceleration:
f ( xi 1 )  2 f ( xi )  f ( xi 1 )
f "( xi ) 
h2
f ( x6 )  2 f ( x5 )  f ( x4 )
f "( x5 ) 
h2
f (12)  2 f (10)  f (8) 7.3  2  6.3  5.1 2
f "(10)  2
 2
 0.05( m / s )
2 2 27

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

Problem3. Determine y’(1) and y”(1) of = ,


with h = 0.1.

Results:
1 = −0.17824017
"(1) = 0.3573462

28

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.3 Lagrange Interpolating Polynomials


The Lagrange interpolating polynomial is simply a reformulation
of the Newton polynomial that avoids the computation of divided
differences. It can be represented concisely as
n
f n ( x)   Li ( x) f ( xi )
i 0
where
n x  xj
Li ( x)  
j 0 xi  x j
j i

29

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

3.3 Lagrange Interpolating Polynomials


Example 3.9: Use a Lagrange interpolating polynomial of the first
and second order to evaluate f(x) = ln(x) at x = 2 on the basis of the
data given as:
x0  1 f ( x0 )  0
x1  4 f ( x1 )  1.386294
x2  6 f ( x2 )  1.791760
Solution:
The first-order polynomial can be used to obtain the estimate at x = 2
24 2 1
f1 (2)  0 1.386294  0.4620981
1 4 4 1
Similarly, the second-order polynomial is developed as:
(2  4)(2  6) (2  1)(2  6) (2  1)(2  4)
f 2 (2)  0 1.386294  1.791760  0.5658444
(1  4)(1  6) (4  1)(4  6) (6  1)(6  4)
30

Department of Machine Design - Faculty of Mechanical Engineering


Ho Chi Minh City University of Technology (HCMUT), VNU-HCM

31

Department of Machine Design - Faculty of Mechanical Engineering

You might also like