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

ME 361-Integration

The document discusses numerical integration techniques for approximating the definite integral of a function between bounds. It introduces replacing the function with a simple approximating function, and describes the trapezoidal rule, Simpson's 1/3 rule, and Simpson's 3/8 rule for approximating integrals using linear, quadratic, and cubic interpolating polynomials. It provides the general Newton-Cotes formulae and examples applying the rules to calculate definite integrals.

Uploaded by

Yigit YAMAN
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)
58 views

ME 361-Integration

The document discusses numerical integration techniques for approximating the definite integral of a function between bounds. It introduces replacing the function with a simple approximating function, and describes the trapezoidal rule, Simpson's 1/3 rule, and Simpson's 3/8 rule for approximating integrals using linear, quadratic, and cubic interpolating polynomials. It provides the general Newton-Cotes formulae and examples applying the rules to calculate definite integrals.

Uploaded by

Yigit YAMAN
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/ 45

ME – 361 NUMERICAL METHODS FOR ENGINEERS

Numerical Integration

Given a complicated f(x) or a set of tabulated values, xi’s and corresponding f(xi)’s:

b
Question: For a given range, [a,b]  f (x) dx = ?
a

Answer: Replace f (x) or the tabulated data with a simple function g(x) and
operate on g(x), instead

b b
f (x)  g (x) ,  f (x) dx
a
  g(x) dx
a

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

x i+1 x i+1

 f(x) dx
xi
  P (x) dx
xi
1

h
 h f(x i ) + f(x i+1 ) - f(x i ) 
2
h
 f(x i ) + f(x i+1 ) 
2
h
 f i + f i+1 
2

0
Trapezoidal Rule

Δx = h
h
 f 0  2 f1  2 f 2  ...  2 f n-1  f n 
xn
x
0
f (x) d x 
2
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Second-degree
Polynomials, P2(x) x2 x2

 f(x) dx
x0
  P (x) dx
x0
2

s (s - 1) 2
P2 (x) = f0 + s Δf0 + Δ f0
2!

x - x0
s=
h

Simpson's One-third Rule

h
f 0  4 f1  2 f 2  ...  2 f n-2  4 f n-1  f n 
xn

x0
f (x) d x 
3
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Newton - Cotes Formulae

Trapezoidal Rule (set of first-degree polynomials)

h - (x n - x 0 )3 ' '
 f  2 f1  2 f 2  ...  2 f n-1  f n 
xn
x 0
f (x) d x 
2 0
E trap 
12 n 2
f ( )

Simpson's One-third Rule (set of second-degree polynomials)

f (x) d x  f 0  4 f1  2 f 2  ...  2 f n -2  4 f n -1  f n 
xn h - (x n - x 0 )5 (4)
x0 3
E1/3 
180 n 4 f ( )

Simpson's Three-eights Rule (set of third-degree polynomials)

3h
 f0  3 f1  3 f 2  2 f3  ...  2 f n-3  3 f n-2  3 f n-1  f n 
xn
x 0
f (x) d x 
8

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Thomas Simpson FRS

Fellow of the Royal Society

1710 - 1761

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Difference Table for f (x) = e-x

x f (x) Δf Δ2 f Δ3 f Δ4 f
0 1
- 0.632120559
1 0.367879441 0.399576401
- 0.232544158 - 0.252580458
2 0.135335283 0.146995943 0.1596613
- 0.085548215 - 0.092919158
3 0.049787068 0.054076785 0.05873611
- 0.031471429 - 0.034183048
4 0.018315639 0.019893738 0.021607807
- 0.011577692 - 0.012575241
5 0.006737947 0.007318497
- 0.004259195
6 0.002478752
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 1 2 3 4 5 6
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

6 6
Example: Find the integral 
0

I = e  x dx = f(x) dx
0
using forward-difference table

I True Relative Error


Exact 0.997521
Trap Rule 1.07929 8%

Simpson’s 1/3 Rule 1.00247 0.5 %

Simpson’s 3/8 Rule 1.00757 1%

Note that Simpson’s 1/3 rule requires odd number of data points (even number of
panels), multiples of three, and that Simpson’s 3/8 rule requires even number of
data points (odd number of panels), multiples of four. Otherwise, use a combination
of the rules.
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Richardson’s Extrapolation

Trap-rule formula:

b - a b - a    b - a  ''
3
1 1 n 1

 2 f a  2 f b   f  a + n i   - 12 n 2 f ( )
b
I=  a
f(x) dx 
n  i 1  

Note that the error is roughly proportional to n2, where n is the number of panels.

Let’s denote the true integral by I*. Find I with trap rule using first with n1 number of
panels and then with n2 number of panels

b - a  b - a 
3 3
*
I = I n1 + E n1 = I n1 - f (1 )
''
I* = I n2 + E n2 = I n2 - f '' ( 2 )
12 n12 12 n 22

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

I* - I n2 = E n2 I* - I n2
 
E n2 * *
E n2
=> *
= => I - I n2 = I - I n1
*
I - I n1 = E n1 I - I n1 E n1 E n1

b - a 
3

- f '' ( 2 ) 2 2
Take the ratio of E n2 12 n 2
 n1  f '' ( 2 )  n1 
= 2
=     
 b - a  '' f (1 )
3 ''
two errors. E n1  n2   n2 
- 2
f (1 )
12 n1

2
 n1 
 
I n2 - I n1
I* - I n2  I* - I n1   Solve for I*: I  I n1 +
*
2
 n2  n 
1-  1
 n2 

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

3 3

 x  
3
Example: Find the integral I= - 2 x 2 + 7 x - 5 dx = f(x) dx
1 1

2
Exact solution: I = 20
3

Richardson’s extrapolation using n1 = 2 and n2 = 4:

3 - 1 1 1  1 25 
In1 =  f(1) + f(3) + f(2)  =  + + 9  = 22
2 2 2  2 2 

3 - 1 1 1 
In1 = f(1) + f(3) + f(1.5) + f(2) + f(2.5)  = 21
4  2 2 

21 - 22 2
I*  22  2
= 20 Why did we get the exact answer?
2 3
1-  
4

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Romberg Integration Table

1  b-a 2N - 1
 b-a 
TN , 1   N-1 , 1
2 
T 
2 N-1

i=1
f a + N
 2
i

, i = 2

4 j - 1 TN+1 , j-1 - TN , j-1


TN , j = j-1
, j = 2, 3, ...
4 -1

where T N , j : Estimate of an integral

n = 2 N panels

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

1
n
Example: I =  e- x dx N j=1 j=2 j=3
(Panels)
0

Exact I = 0.63212 1 0 0.6839 0.6323 0.6321

2 1 0.6452 0.6321 0.6321


4 2 0.6354 0.6321 0.6321
8 3 0.6329 0.6321
16 4 0.6323

Accuracy T-T  

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Monte Carlo Integration

Example:

The error function is defined by


x
2
e
t 2
Erf(x) = dt
 0

The integral must be obtained, numerically. It is given in tabular form for different
values of x, from which Erf(1) = 0.84270

• Use Monte-Carlo method to evaluate the integral. Choose N = 100 and N =


500, and compare with the true value.

• Use Gauss-Legendre quadrature method to evaluate the same integral.


Choose N = 3 and N = 6, and compare with the true.

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

1.10

1.00

0.90

N =100
0.80

I = 0.73
0.70

0.60

0.50

0.40
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

1.10

1.00

0.90

0.80 N = 500

0.70
I = 0.81

0.60

0.50

0.40
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Prof. Dr. Faruk Arınç Fall 2020


ME – 510 NUMERICAL METHODS FOR ME II

Gauss(ian) Quadrature Methods

b n
Newton-Cotes Formulae: I   f (x) dx  w
i0
i f (x i )
a

The range, (a,b), is divided into equal spacings (panels).


A polynomial of small degree passes through these equally-spaced points.

Why equal spacing?


Does the function has to be a polynomial?
b N b

Error in Newton-Cotes Formulae: I =  f(x) dx = w i 1


i f(x i ) +  g(x) h(x) dx
a a

Exact Approx. How to minimize?


Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Gauss(ian) Quadrature Methods

b n
I   f (x) dx   wi f (xi )
a i0

n + 1 values of wi There are 2 n + 2 parameters which define a


=>
n + 1 values of f (xi) polynomial of degree 2 n + 1

n b
Choose xi’s such that, the sum  w i f (x i ) gives the integral  f (x) dx
i0 a

exactly when f (x) is already a polynomial of degree 2 n + 1.

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Johann Carl Friedrich Gauss

1777 – 1855

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example f(x) = 3 x 2 + 2 x + 1

4 4
Iex =  f(x) dx = 81 Itrap =  f(x) dx = 81.375 with h = 0.5 => 6 panels
1 1

60

50

40

30

20

10

0
Prof. Dr. Faruk Arınç
1.0 1.5 2.0 2.5 3.0 3.5 4.0 Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

60

50

40
f(x) = 3 x 2 + 2 x + 1
30

f(x2)
20

10
f(x1)
0
1.0 1.5 2.0 2.5 3.0 3.5 4.0

4 N
Iex =  f(x) dx = 81 I= w
i 1
i f(x i ) = Iex N=2 xi = ? wi = ?
1
Nodes and weights

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Infinite Set of Orthogonal Functions

Two functions, f(x) and g(x), both real-valued and continous, are called orthogonal
to each other with respect to a third (weighting) function, w(x), in the range [a,b] if
b
I   w(x) f(x) g(x) dx
a
 0

1
Examples:  (1) sin(n  x) sin(m  x) dx
0
 0 when n  m

{sin(n x) , n = 1, 2, ... }

1 Fourier
 (1) cos(n  x) cos(m  x) dx
0
 0 when n  m Series

{cos(n x) , n = 0, 1, ... }
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Jean-Baptiste Joseph Fourier

French Mathematician

1768 -1830

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Expansion of f(x) in terms of infinite set of orthogonal functions

Suppose the functions, Qn(x), forms an orthogonal set, n -> inf.

f(x) = c 0 Q0 (x) + c1 Q1(x) + c 2 Q 2 (x) + ... + cn Qn (x) + ....

 w(x) Q (x) f(x) dx =


a
n

 w(x) Q (x)  c
a
n 0 Q0 (x) + c1 Q1(x) + c 2 Q2 (x) + ... + c n Qn (x) + ....  dx

=  w(x) Qn (x)  c n Qn (x)  dx


a

 w(x) Q (x) f(x) dx


a
n

cn = b

 w(x) Q (x) dx
2
n
Prof. Dr. Faruk Arınç a Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example

Expand the function f(x) = 1 in Fourier sine series in the range [0,1], i.e., find the
coefficients, an’s, in the orthogonal expansion

f(x) = a
0
n sin(n x)

The orthogonality property:

1
1 2
 sin  n x  dx = - [ cos n x  0 ] =
1
if n is odd
0
n n
=0 if n is even

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

4 4 4
Solution: f(x) = 1 = sin( x) + sin(2 x) + sin(3 x) + ....
 3 5

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Infinite Set of Orthogonal Polynomials

Legendre polynomials, which form an infinite set, have this property when w(x) = 1
and the range [-1,+1]

 (1) P (x) P (x) dx


-1
n m  0 , n  m

1
P0(x) = 1 P1(x) = x P2 (x)  (3 x 2 - 1)
2

1 1 1
P3 (x)  (5 x 3 - 3 x) P4 (x)  (35 x 4 - 30 x 2  3) P5 (x)  (63 x 5 - 70 x 3  15 x)
2 8 8

{Pn (x) , n = 0, 1, ... }

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Adrien-Marie Legendre

French mathematician

1752 – 1833

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Legendre Polynomials

1
P0(x) = 1 P1(x) = x P2 (x)  (3 x 2 - 1)
2

1 1 1
P3 (x)  (5 x 3 - 3 x) P4 (x)  (35 x 4 - 30 x 2  3) P5 (x)  (63 x 5 - 70 x 3  15 x)
2 8 8

Chebyshev Polynomials

T0(x) = 1 T1(x) = x T2(x) = 2 x2 - 1

T3(x) = 4 x3 - 3 x T4(x) = 8 x4 - 8 x2 + 1 T5(x) = 16 x5 - 20 x3 + 5 x

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Pafnuty Lvovich Chebyshev

Russian mathematician

1821 - 1894

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Laguerre Polynomials

1 2
L (x)  1
0
0 L (x)  - x  1
0
1
L02 (x)  (x  4 x  2)
2

1 1 4
L (x)  (- x 3  9 x 2  18 x  6)
0
3
L04 (x)  (x  16 x 3  72 x 2  96 x  24)
6 24

Hermite Polynomials

H0(x) = 1 H1(x) = 2 x H2(x) = 4 x2 - 2

H3(x) = 8 x3 - 12 x H4(x) = 16 x4 - 48 x2 + 12 H5(x) = 32 x5 - 160 x3 + 120 x

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Admond Nicolas Laguerre

French mathematician

1834 – 1886

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Charles Hermite

French mathematician

1822 - 1901

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

ORTHOGONAL POLYNOMIALS

Name Range of Weighting Integral Property


Orthogonality Function
1
2
Legendre [- 1 , + 1] w(x) = 1  w Pk Pk dx 
-1
2 k 1
1

1 w T k Tk dx   if k  0
Chebyshev [- 1 , + 1] w(x) = -1
2
1-x 1

 w Tk Tk dx 
-1
2
if k  0


 (  k  1)

 
Laguerre [0 , ∞ ] w (x) = xα e-x w L k L k dx 
0
k!



w (x)  e 
-x2
Hermite [- ∞ , +∞ ] w H k H k dx   2 k
k!
-

Prof. Dr. Faruk Arınç Fall 2020


ME – 510 NUMERICAL METHODS FOR ME II

Gauss - Legendre Quadrature Method

b +1 N
I   f(x) dx =  F(z) dz  w
i1
i F(z i ) , N = 2, 3, ....
a -1

N
I  w
i1
i F(z i ) if F  z i  is a polynomial of degree 2 N -1 or LESS

x=
b - a  z+b+a
, dx =
b-a
dz
Change of Variable:
2 2

zi’s are the roots of the Legendre polynomial, PN(z) = 0

zi’s and wi’s are given in mathematical handbooks as tabulated values

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

2x-b-a 2
Define a new independent variable: z = dz = dx
b-a b-a
b 1

Find dz and F(z) I =  f(x) dx =  F(z) dz


a 1

Choose N

Find nodes (xi) and weights (wi) from tabulated data

The nodes (xi) are the zeros of Legendre orthogonal polynomials, which are
orthogonal in the range, (-1, +1)

b 1 N
I =  f(x) dx =  F(z) dz  w
i 1
i F(zi )
a 1

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Gauss-Legendre Nodes and Weights

N ± zi wi
N ± zi wi
2 0.5773502692 1.0000000000
0.1834346425 0.3626837834
0.0000000000 0.8888888889
3 0.5255324099 0.3137066459
0.7745966692 0.5555555556 8
0.7966664774 0.2223810345
0.3399810436 0.6521451549
4 0.9602898565 0.1012285363
0.8611363116 0.3478548451
0.0000000000 0.3302393550
0.0000000000 0.5688888889
0.3242534234 0.3123470770
5 0.5384693101 0.4786286705
9 0.6133714327 0.2606106964
0.9061798459 0.2369268850
0.8360311073 0.1806481607
0.2386191861 0.4679139346
0.9681602395 0.0812743884
6 0.6612093865 0.3607615730
0.1488743390 0.2955242247
0.9324695142 0.1713244924
0.4333953941 0.2692667193
0.0000000000 0.4179591837
10 0.6794095683 0.2190863625
0.4058451514 0.3818300505
7 0.8650633667 0.1495513492
0.7415311856 0.2797053915
0.9739065285 0.0666713443
0.9491079123 0.1294849662
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

Examples:

Exact G-L nodes G-L


Integral Comments
Solution & weights Solution

4 2 4 Exact result

81 2 81 Exact result

0.9975212 2 0.8706496 Low accuracy

0.9975212 4 0.9971697 More accurate

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Example

6 6 N 2
I =  e dx =  f(x) dx 
-x
w
i 1
i F(zi ) = w 1 F(z1) + w 2 F(z 2 )
0 0

2x-b-a 2x-6 x-3


z= = = => x = 3 (z + 1) dx = 3 dz
b-a 6 3

6 1

I =  e dx = 3
-x
 e -3(z+1)
dz  3 
 e -3(z1 +1)
+ e -3(z 2 +1)

0 1

1
z1,2 =  =  0.5773502692 I  0.8706496
3
Iexact  0.9975212

12.7 % error with only 2 nodes and weights

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Error expression for Gauss-Legendre quadrature method:

22 N  1 N !
4

E f (2N)   , - 1   1
(2 N  1) 2 N !
3

where N is the number of nodes and weights used.

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

GAUSS QUADRATURE METHODS

Name Quadrature Formula

 1 N
Gauss-Legendre  f (x) dx  w
i1
i f (x i )
-1

 1 N
1
Gauss-Chebyshev  2
f (x) dx  w i f (x i )
-1 1-x i1

 N
Gauss-Laguerre e
-x
f (x) dx  w
i1
i f (x i )
0

 N
Gauss-Hermite e
- x2
f (x) dx  w
i1
i f (x i )
-

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

GAUSS QUADRATURE METHODS

Name Nodes and Weights

N  xi wi

2 0.577350269 1.00000000
0 0.888888889
Gauss-Legendre 3
0.774596669 0.555555556

0.339981043 0.652145155
4
0.861136312 0.347854845

 1 
i-  
Gauss-Chebyshev x i  cos  2  i  1, 2, ... N wi = for all i
 N  N
 
 
Prof. Dr. Faruk Arınç Fall 2020
ME – 361 NUMERICAL METHODS FOR ENGINEERS

N xi wi

0.58578 64376 0.85355 33906


2
3.41421 35624 0.14644 66094
0.41577 45568 0.71109 30099
Gauss-Laguerre 3 2.29428 03603 0.27851 77336
6.28994 50829 0.01038 92565
0.32254 76896 0.60315 41043
1.74576 11012 0.35741 86924
4
4.53662 02969 0.03888 79085
9.39507 09123 0.00053 92947

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

N  xi wi
2 0.70710 67811 0.88622 69255
0. 1.18163 59006
3
1.22474 48714 0.29540 89752
Gauss-Hermite
0.52464 76233 0.80491 40900
4
1.65068 01239 0.08131 28354
0. 0.94530 87205
5 0.95857 24646 0.39361 93232
2.02018 28705 0.01995 32421

Prof. Dr. Faruk Arınç Fall 2020


ME – 361 NUMERICAL METHODS FOR ENGINEERS

Prof. Dr. Faruk Arınç Fall 2020

You might also like