Numerical Integration: Basic Rule
CS/SE 4X03
Ned Nedialkov McMaster University February 11, 2021
Outline
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors The problem
• Approximate numerically the integral b
If =
• Closed form may not exist, e.g. b e−x2 dx, or may be difficult
to compute
• The integrand f(x) may be known only at certain points obtained via sampling (e.g. embedded applications)
a
f(x)dx a
Copyright © 2021 N. Nedialkov. All rights reserved. 3/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Derivation
Errors
If =
b n f(x)dx ≈
ajf(xj)
• The sum is called a quadrature rule • The aj are weights
• How to find them?
a
j=0
Copyright © 2021 N. Nedialkov. All rights reserved. 4/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors Derivation cont.
• Let x0,…,xn be distinct points in [a,b]
• Let pn(x) be the interpolating polynomial for f(x) through
these points
• b pn(x)dx ≈ b f(x)dx aa
• From the Lagrange form pn(x) = nj=0 f(xj)Lj(x),
b b b n f(x)dx ≈ pn(x)dx =
a a aj=0
f(xj)Lj(x)dx
=
Lj(x)dx
n b f(xj)
j=0
a
aj
• aj =bLj(x)dx a
Copyright © 2021 N. Nedialkov. All rights reserved. 5/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Trapezoidal rule
Letn=1. Thenx0 =aandx1 =b L0(x)=x−x1 =x−b
b
a0 = L0(x)dx=
aa
Errors
x0 − x1 a − b
bx−b b−a
a−bdx= 2 bx−a b−a
L1(x)=x−x0 =x−a x1 − x0 b − a
b
a1 = L1(x)dx=
b−adx= 2
If ≈ a0f(x0) + a1f(x1) = b − af(a) + f(b)
aa
2
If ≈Itrap = b−af(a)+f(b) 2
Copyright © 2021 N. Nedialkov. All rights reserved. 6/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors Trapezoidal rule cont.
Example 1.
• Approximate1exdx=e−1≈1.7182…usingthe
0
trapezoidal rule:
Itrap = 1[f(0)+f(1)]=0.5(1+e)=1.8591… 2
• Approximate 0.1 exdx = e0.1 − 1 ≈ 0.10517 . . . using the 0
trapezoidal rule:
Itrap = 0.1[f(0)+f(0.1)]=0.051+e0.1=0.10525… 2
Copyright © 2021 N. Nedialkov. All rights reserved. 7/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors Simpson’s rule
Letn=2,andx0 =a,x1 =(a+b)/2,x2 =b
b − a a + b
If ≈ISimpson = 6 f(a)+4f 2 +f(b) Example 2.
• Approximate 1 exdx = e − 1 ≈ 1.71828 . . . using Simpson’s 0
rule:
ISimpson = 1[f(0)+4f(0.5)+f(1)]= 1(1+4e0.5 +e) 66
= 1.71886 . . .
Copyright © 2021 N. Nedialkov. All rights reserved. 8/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule Errors Midpoint rule
Letn=0,x0 =(a+b)/2 Then
a+b If ≈Imid =(b−a)f 2
Example 3.
• Approximate1exdx=e−1≈1.7182…usingthemidpoint
0
rule:
• Approximate 0.1 exdx = e0.1 − 1 ≈ 0.10517 . . . using the
Imid =f(0.5)=1.6487… 0
midpoint rule:
Imid = 0.1f (0.05) = 0.05e0.05 = 0.10512 . . .
Copyright © 2021 N. Nedialkov. All rights reserved. 9/10
The problem Derivation Trapezoidal rule Simpson’s rule Midpoint rule
Errors
• E(f)=bf(x)dx−n ajf(xj) a j=0
• Trapezoidal rule
E(f)=−f′′(η)(b−a)3, η∈(a,b)
12
• Midpoint rule
E(f)=f′′(ζ)(b−a)3, ζ∈(a,b)
24
Errors
• Simpson’s rule
E(f) = − 90 2 , ξ ∈ (a,b)
f(4)(ξ) b − a5 Copyright © 2021 N. Nedialkov. All rights reserved.
10/10