0% found this document useful (0 votes)
7 views17 pages

4.3 - Elements of Numerical Integration

This section covers the elements of numerical integration, focusing on the derivation and implementation of the Trapezoidal and Simpson rules for approximating definite integrals. It also discusses evaluating error bounds associated with these methods. Numerical integration is particularly useful for functions lacking explicit antiderivatives.

Uploaded by

vqqh5fnvfh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views17 pages

4.3 - Elements of Numerical Integration

This section covers the elements of numerical integration, focusing on the derivation and implementation of the Trapezoidal and Simpson rules for approximating definite integrals. It also discusses evaluating error bounds associated with these methods. Numerical integration is particularly useful for functions lacking explicit antiderivatives.

Uploaded by

vqqh5fnvfh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Sec:4.

Elements of Numerical
Integration
Sec:4.3 Elements of Numerical Integration

In this section, we shall discuss the following items:

1. The derivation and implementation of the Trapezoidal rule


for approximating the definite integral.

2. The derivation and implementation of Simpson rule for


approximating the definite integral.

3. Evaluating the error bounds on approximating the definite


integrals.
Sec:4.3 Elements of Numerical Integration

Question: What is the meaning of numerical integration?

Answer: It is the process of approximating the definite integral of a function at a certain


interval using a set of discrete points .

Remark
 Numerical integration is useful for approximating a definite integral of a function that has
no explicit antiderivative or whose antiderivative is not easy to obtain.

 The basic method for approximating is called numerical quadrature. It uses a sum to
approximate .
Sec:4.3 Elements of Numerical Integration

Derivation
The derivation of the quadrature methods (Trapezoidal and Simpson rules) will be
based on the Lagrange interpolating polynomials discussed in Chapter 3.

Weighted Mean Value Theorem for


Integrals

Suppose f ∈ C[a, b], the Riemann integral


of g exists on [a, b], and g(x) does not
change sign on [a, b]. Then there exists a
number c in (a, b) with

𝑏 𝑏

∫ 𝑓 ( 𝑥 ) 𝑔 ( 𝑥 ) 𝑑𝑥= 𝒇 ( 𝒄)∫ 𝑔 ( 𝑥 ) 𝑑𝑥
𝑎 𝑎
Sec:4.3 Elements of Numerical IntegrationDerivation for The Trapezoidal Rul

Derivation of Trapezoidal Rule


Using first Lagrange polynomials 𝑥 0=𝑎 h=𝑏 − 𝑎 𝑥1 =𝑏

𝑓 ( 𝑥 ) =𝑷 𝟏 ( 𝒙 ) + 𝑹𝟏 ( 𝒙 )

′′
𝒇 (𝝃 )
𝑓 ( 𝑥 ) =𝒇 ( 𝒙 𝟎 ) 𝑳 𝟎( 𝒙 )+ 𝒇 ( 𝒙 𝟏 ) 𝑳 𝟏( 𝒙 )+ ( 𝒙 − 𝒙 𝟎)( 𝒙 − 𝒙 𝟏 )
𝟐!

𝒙 − 𝒙𝟏 𝒙 − 𝒙𝟎 𝒇 ′ ′ ( 𝝃 )
𝑓 ( 𝑥 ) =𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟏) + ( 𝒙 − 𝒙 𝟎)( 𝒙 − 𝒙 𝟏)
𝒙𝟎 − 𝒙 𝟏 𝒙𝟏− 𝒙𝟎 𝟐!

𝑏 𝒙𝟏 𝒙𝟏 𝒙𝟏 ′′
𝒇 (𝝃 )
∫ 𝑓 ( 𝑥 ) 𝑑𝑥= 𝒇 ( 𝒙 𝟎∫ 𝟎
) 𝑳 ( 𝒙 ) 𝒅𝒙 + 𝒇 ( 𝒙 𝟏 ∫ 𝟏
) 𝑳 ( 𝒙 ) 𝒅𝒙 +¿ ∫ 𝟐! (𝒙 − 𝒙 𝟎)(𝒙 − 𝒙𝟏 ) dx ¿
𝑎 𝒙 𝟎 𝒙 𝟎 𝒙 𝟎

𝑏 𝒙𝟏 ′′
1 𝒇 (𝝃)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
2
h [ 𝒇 ( 𝒙 𝟎) + 𝒇 ( 𝒙 𝟏 )] ∫
+
𝟐!
(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 ) dx
𝑎 𝒙 𝟎

[ ]
𝒙𝟏 𝒙𝟏 𝒙𝟏 𝟐 𝒙𝟏

𝒙 𝟎
𝒙
𝒙−𝒙
𝟎𝟎
𝟏
𝟏
∫ 𝑳𝟎 ( 𝒙 ) 𝒅𝒙=∫ 𝒙 − 𝒙𝟏 𝒅𝒙= −𝒉
𝒙 𝟎
( 𝒙−𝒙 )
∫ ( 𝒙 − 𝒙 𝟏) 𝒅𝒙=− 𝒉𝟏 𝟐 𝟏
𝒙𝟎
( )[
=−
𝟏
𝒉
𝟏 𝟐
𝟐
𝟏
𝟐]
𝟎− 𝒉 =¿ 𝒉 ¿

[ ] ( )[
𝒙𝟏 𝒙𝟏 𝒙𝟏 𝟐 𝒙𝟏

∫ 𝟏
𝒙𝟎
𝑳 ( 𝒙 ) 𝒅𝒙 =
𝒙
𝒙 − 𝒙𝟎
∫ 𝒙 −𝒙
𝟏
𝟎
𝟎
𝒅𝒙=
𝟏
𝒉𝒙
∫ ( 𝟎) 𝒉 𝟐
𝒙
𝟎
− 𝒙 𝒅𝒙 =
𝟏 ( 𝒙 − 𝒙𝟎 )
𝒙𝟎
=
𝟏 𝟏 𝟐
𝒉 𝟐
𝟏
𝒉 − 𝟎 =¿ 𝒉 ¿
𝟐 ]
Sec:4.3 Elements of Numerical Integration Error for The Trapezoidal Rule

The Trapezoidal Rule Weighted Mean Value


𝑏 𝒙𝟏 ′′
Theorem for Integrals
1 𝒇 (𝝃) Suppose f ∈ C[a, b], the
∫ 𝑓 𝑥 𝑑𝑥= 2 h [ 𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟏 ) ] +∫ 𝟐 ! (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 ) dx (1)
( ) Riemann integral of g exists on
𝑎 𝒙
𝟎 [a, b], and g(x) does not change
sign on [a, b]. Then there exists
a number c in (a, b) with
𝒙𝟏 ′′ 𝒙𝟏
𝒇 (𝝃) 𝟏 ′′ 𝑏 𝑏

∫ 𝟐! (𝒙 − 𝒙 𝟎 )(𝒙 − 𝒙 𝟏) dx= 𝟐 ∫ 𝒇 ( 𝝃 (𝒙)) ( 𝒙 − 𝒙 𝟎)( 𝒙 − 𝒙 𝟏) dx ∫ 𝑓 ( 𝑥 ) 𝑔 ( 𝑥 ) 𝑑𝑥= 𝑓 (𝑐)∫ 𝑔 ( 𝑥 ) 𝑑𝑥


𝑎 𝑎
𝒙𝟎 𝒙 𝟎

The Weighted Mean Value Theorem for Does not change its sign

[ ]
Integrals ′′ 𝒙𝟏
𝒇 ′′ ( 𝝃 )
𝒇 (𝒄) 𝒉
𝟑
𝒉
𝟑

𝟐 ∫
¿ (𝒙 − 𝒙 𝟎 )(𝒙 − 𝒙 𝟏) dx ¿ − =− 𝒇 ′ ′ ( 𝒄 ) (𝟐)
𝟐 𝟔 𝟏𝟐
𝒙
Substituting (2) into (1), we get 𝟎

𝑏 𝟑
1 𝒉 ′′
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
2
h [ ( 𝟎 ) ( 𝟏 ) ] 𝟏𝟐 𝒇 ( 𝒄 )
𝒇 𝒙 + 𝒇 𝒙 −
𝑎

Dropping the error term, we get the Trapezoidal rule as follows:


𝑏
1
∫ 𝑓 ( 𝑥 ) 𝑑𝑥 ≈ 2
h [ 𝒇 ( 𝒙𝟎 ) + 𝒇 ( 𝒙 𝟏 ) ]
𝑎
Sec:4.3 Elements of Numerical Integration
Trapezoidal Rule
𝑏 h=𝑏
h=𝑏 𝑎𝑎
−−
1
∫ 𝑓 ( 𝑥 ) 𝑑𝑥 ≈ 2
h [ 𝒇 ( 𝒙𝟎 ) + 𝒇 ( 𝒙 𝟏 ) ]
𝑎

The Trapezoidal rule got this name because when is


positive, is approximated by the area of trapezoid
whose bases of lengths and and height .

Remark

The error term of the Trapezoidal rule involves , so if the Trapezoidal rule applied to any
function whose second derivative is zero, the error term will vanish. Therefore, the
Trapezoidal rule gives exact result for all polynomials of degree one or less.
Sec:4.3 Elements of Numerical Integration

Example
The Trapezoidal Rule
Approximate the integral
using the Trapezoidal 𝑏 𝒉=𝒃 − 𝒂
rule 2
∫ 𝑓 ( 𝑥 ) 𝑑𝑥 ≈ 𝒉
𝟐
[ 𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟏) ]
𝑎
∫ 𝑥 𝑑𝑥
2

2
𝑓 ( 𝑥 ) =𝑥 , h= 2 , 𝑎=0 , 𝑏=2

∫ 𝑥 2 𝑑𝑥 ≈ 𝟏𝟐 𝒉 [ 𝒇 ( 𝒙 𝟎 ) + 𝒇 ( 𝒙 𝟏) ]
0

𝟏
𝟐 [
≈ 𝒉 𝒇 ( 𝒙 𝟎) + 𝒇 ( 𝒙𝟏 ) ]

𝟏
≈ ( 𝟐) [ 𝟎+ 𝟒 ]
𝟐
≈𝟒
Sec:4.3 Elements of Numerical Integration
Sec:4.3 Elements of Numerical Integration Simpson’s Rule Derivation

Derivation of Simpson Rule


Another quadrature method for approximating the definite integral is called the Simpson rule.
It can be derived based on the second Lagrange interpolating polynomial.
𝑥 0=𝑎 𝑥1 = 𝑥0 + h 𝑥 2=𝑏
Using second Lagrange polynomials
𝑓 ( 𝑥 ) = 𝑷 𝟐 ( 𝒙 ) + 𝑹𝟐 ( 𝒙 ) 𝒃− 𝒂
𝒉=
𝟐

𝒙𝟐 𝒙𝟐 𝒙𝟐 𝒙𝟐 ′ ′′
𝑏
𝒇 ( 𝝃𝟏)
∫ 𝑓 𝑥 𝑑𝑥= 𝒇 ( 𝒙 𝟎 )∫ 𝑳𝟎 𝒙 𝒅𝒙 + 𝒇 ( 𝒙𝟏 ) ∫ 𝑳𝟏 𝒙 𝒅 𝑥+ 𝒇 ( 𝒙 𝟐 )∫ 𝑳𝟐 𝒙 𝒅𝒙+¿ ∫ 𝟑! (𝒙 − 𝒙 𝟎)(𝒙 − 𝒙 𝟏)( 𝒙 − 𝒙 𝟐)dx ¿
( ) ( ) ( ) ( )
𝑎 𝒙 𝟎 𝒙 𝟎 𝒙 𝟎 𝒙 𝟎

𝒙𝟐 ′′ ′
𝒇 ( 𝝃𝟏)
¿ 𝒂𝟎 𝒇 ( 𝒙𝟎 ) +𝒂 𝟏 𝒇 ( 𝒙𝟏 ) +𝒂 𝟐 𝒇 ( 𝒙𝟐 ) +∫ (𝒙 − 𝒙 𝟎)(𝒙 − 𝒙 𝟏)(𝒙 − 𝒙𝟐 )dx (3)
𝟎 𝒙
𝟑!
𝒙𝟐 𝒙𝟐 𝒙𝟐
𝒉 𝟒𝒉 𝒉
𝒂𝟎=∫ 𝑳 𝟎 𝒙 𝒅𝒙=¿ ¿
( ) 𝒂𝟏=∫ 𝑳𝟏 𝒙 𝒅𝒙=¿
( ) ¿ 𝒂𝟐=∫ 𝑳𝟐 ( 𝒙 ) 𝒅𝒙=¿ ( 𝟒) ¿
𝒙 𝟎
𝟑 𝒙 𝟎
𝟑 𝒙𝟎
𝟑
Substituting (4) into 3, we get
𝒙𝟐 ′′ ′
𝑏
𝒉 𝒇 ( 𝝃 𝟏)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥= 𝟑 [ 𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏) + 𝒇 ( 𝒙𝟐 ) ] +∫ 𝟑 ! ( 𝒙 − 𝒙 𝟎)( 𝒙 − 𝒙 𝟏)(𝒙 − 𝒙 𝟐)dx
𝑎 𝒙
𝟎
Sec:4.3 Elements of Numerical Integration Simpson’s Rule Derivation

𝒙𝟐 ′′ ′
𝑏
𝒉 𝒇 ( 𝝃 𝟏)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥= 𝟑 [ 𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏) + 𝒇 ( 𝒙𝟐 ) ] +∫ 𝟑 ! ( 𝒙 − 𝒙 𝟎)( 𝒙 − 𝒙 𝟏)(𝒙 − 𝒙 𝟐)dx (𝟓)
𝑎 𝟎 𝒙

It can be shown that the error term in the above formula is as follows:
𝒙𝟐 ′ ′′
𝒇 ( 𝝃𝟏) 𝒉𝟓 ( 𝟒)
∫ 𝟑!
( 𝒙 − 𝒙 𝟎 ) ( 𝒙 − 𝒙𝟏 ) ( 𝒙 − 𝒙 𝟐) dx =−
𝟗𝟎
𝒇 ( 𝝃 ∗ ) , 𝝃 ∗ ∈ ( 𝒙 𝟎 , 𝒙 𝟐 ) ( 𝟔)
𝒙𝟎

Setting (6) into (5), we get,


𝑏 𝟓
𝒉 𝒉
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
𝟑
[ 𝒇 ( 𝒙 𝟎) +𝟒 𝒇 ( 𝒙 𝟏) + 𝒇 ( 𝒙 𝟐) ] −
𝟗𝟎
𝒇
(𝟒 )
( 𝝃∗)
𝑎

Dropping the error term from the above formula, we get the Simpson rule as follows:

Simpson Rule
𝒃− 𝒂
𝒉 𝒉=
𝑓 ( 𝑥 ) 𝑑𝑥 ≈
𝟑
[ 𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏 ) + 𝒇 ( 𝒙 𝟐 ) ]𝟐
Sec:4.3 Elements of Numerical Integration Simpson’s Rule Derivation

Simpson Rule
𝒃− 𝒂
𝒉=
𝒉 𝟐
𝑥 ) 𝑑𝑥 ≈
𝟑
[ 𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏 ) + 𝒇 ( 𝒙 𝟐 ) ]

Remark

The error term of Simpson rule involves , so if Simpson rule applied to any function whose
fourth derivative is zero, the error term will vanish. Therefore, Simpson rule gives exact
result for all polynomials of degree three or less.

Remark
The Trapezoidal and Simpson rules are subclasses of methods know as Newton-Cotes
Methods.
Sec:4.3 Elements of Numerical Integration

Example Simpson’s Rule


Approximate the integral 𝑏 𝒃− 𝒂
𝒉 𝒉=
using the Simpson’s rule
∫ 𝑓 ( 𝑥 ) 𝑑𝑥 ≈
𝟑
𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏 ) + 𝒇 ( 𝒙 𝟐) 𝟐
[ ]
2 𝑎

∫ 𝑥 2 𝑑𝑥
0

2
𝑓 ( 𝑥 ) =𝑥 , h= 1 , 𝑥 0= 0 , 𝑥 1=1 , 𝑥 2 =2

2
𝒉
∫ 𝑥
2
𝑑𝑥 ≈
𝟑
[ 𝒇 ( 𝒙 𝟎 ) +𝟒 𝒇 ( 𝒙 𝟏) + 𝒇 ( 𝒙 𝟐 ) ]
0
𝟏

𝟑
[ 𝒇 ( 𝟎 ) +𝟒 𝒇 ( 𝟏 ) + 𝒇 ( 𝟐 ) ]
𝑥 0=0 𝑥1 =1 𝑥 2=2
𝟏
≈ [ 𝟎+ 𝟒+𝟒 ]
𝟑
𝟖
≈ It is exact
𝟑
Sec:4.3 Elements of Numerical Integration

Notice that in each instance Simpson’s Rule is significantly


superior.
Simpson’s Rule The Trapezoidal Rule
Sec:4.3 Elements of Numerical Integration
Sec:4.3 Elements of Numerical Integration

The Trapezoidal Rule


𝑏 𝟑
𝒉 𝒉 ′′
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
𝟐
[ 𝒇 ( 𝒙 𝟎) + 𝒇 ( 𝒙 𝟏) ] −
𝟏𝟐
𝒇 (𝝃)
𝑎

h=𝑏 − 𝑎

Simpson’s Rule
𝑏 𝟓
𝒉 𝒉 ( 𝟒)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
𝟑
[ 𝒇 ( 𝒙 𝟎) +𝟒 𝒇 ( 𝒙 𝟏) + 𝒇 (𝒙 𝟐 ]
) −
𝟗𝟎
𝒇 ( 𝝃∗)
𝑎

h=(𝑏 −𝑎 )/ 2

1) How to use
2) MATLAB
3) Derivation
Sec:4.3 Elements of Numerical Integration

The Trapezoidal Rule


f = @(x) x^2;
𝑏 𝟑
𝒉 𝒉 ′′ a=0; b=2;
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
𝟐
[ 𝒇 ( 𝒙 𝟎) + 𝒇 ( 𝒙 𝟏) ] −
𝟏𝟐
𝒇 (𝝃) h=b-a;
𝑎
intg = (h/2)*(f(a)+f(b))
h=𝑏 − 𝑎

Simpson’s Rule
f = @(x) x^2;
𝑏 𝟓 a=0; b=2;
𝒉 𝒉 ( 𝟒)
∫ 𝑓 ( 𝑥 ) 𝑑𝑥=
𝟑
[ ( 𝟎 ) ( 𝟏)
𝒇 𝒙 +𝟒 𝒇 𝒙 + 𝒇 (𝒙 𝟐 ]
) −
𝟗𝟎
𝒇 ( 𝝃∗) h=(b-a)/2;
𝑎 x=a:h:b;
intg = (h/3)*(f(x(1))+4*f(x(2))+f(x(3)))
h=(𝑏 −𝑎 )/ 2

You might also like