0% found this document useful (0 votes)
10 views40 pages

Numsol

Uploaded by

onlysandejas
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)
10 views40 pages

Numsol

Uploaded by

onlysandejas
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/ 40

NUMERICAL DIFFERENTIATION

AND INTEGRATION

Source: Numerical Methods for Engineers 7th Edition by Chapra and Canele
NUMERICAL DIFFERENTIATION
• Numerical Differentiation is the process of finding the numerical value of a derivative of a
function at a given point.
• To differentiate means “to mark off by differences; distinguish; . . . to perceive the difference
in or between.”
• Mathematically, the derivative, which serves as the fundamental vehicle for differentiation,
represents the rate of change of a dependent variable with respect to an independent
variable.
• As depicted in the graph, the mathematical definition of the derivative begins with a difference
approximation: where y and f(x) are the dependent variables and x is the independent variable.
∆� �(�� + ∆�) − �(�� )
=
∆� ∆�
NUMERICAL DIFFERENTIATION
• Numerical Differentiation can be solved using the finite divided difference because it is the
approximation of the first derivatives.
�(��+� ) − �(�� )
�’(�� ) =
��+� − ��
• The finite divided difference was used in the taylor series expansion, so technically, numerical differentiation
can be derived using the taylor series. Where h is the step size, the length of the interval over which the
approximation is made.
′ ′′
(� − �)� ′′′
(� − �)�
�(�) = �(�) + � (�)(� − �) + � (�) + � (�) +⋯
�! �! � is the (x-a) from our formula
� �
� � ��+� is the x from our formula
�(��+� ) = �(�� ) + �′ (�� )� + �′′ (�� ) + �′′′ (�� ) + ⋯ �� is the a from our formula
�! �!
• There are three types to differentiate which are called the FINITE DIFFERENCE METHODS; the forward
difference (a), the backward difference (b) and the central difference (c).
NUMERICAL DIFFERENTIATION: FORWARD DIFFERENCE
• Forward Difference. It is called “forward” because it utilizes the i and i+1 to estimate the derivative.
• Derivation. Using the first order approximation of the Taylor series expansion, we can get the first forward divided
difference
′ ′′
�� ′′′
��
�(��+� ) = �(�� ) + � (�� )� + � (�� ) + � (�� ) +⋯
�! �!
�(��+� ) = �(�� ) + �′ (�� )�
�′ (�� )� = �(��+� ) − �(�� )
� �
∗ �′ (�� )� = �(��+� ) − �(�� ) ∗
� �
�(��+� ) − �(�� )
�′ (�� ) =

NUMERICAL DIFFERENTIATION: FORWARD DIFFERENCE
• Derivation. Now we incorporate the additional terms of the Taylor series to have a High Accuracy Divided Difference
Formulas.
′ ′′
�� ′′′
��
�(��+� ) = �(�� ) + � (�� )� + � (�� ) + � (�� ) +⋯
�! �!
′ ′′
��
�(��+� ) = �(�� ) + � (�� )� + � (�� )
�!
′( ) ′′
��
� �� � = �(��+� ) − �(�� ) − � (�� )
�∗�
� ′( ) ′′
�� �
∗ � �� � = �(��+� ) − �(�� ) − � (�� ) ∗
� � �
�(��+� ) − �(�� ) �
�′ (�� ) = − �′′ (�� ) → ��. �
� �
• With these we can incorporate more points to be substituted. When we add more point, the step size (h) will also increase.
Then we can get the value of the �′′ (�� ) in terms of the function of x.
′ ′′
(��)�
�(��+� ) = �(�� ) + � (�� )�� + � (�� )
�!
′ ′′
���
�(��+� ) = �(�� ) + � (�� )�� + � (�� )
�∗�
�(��+� ) = �(�� ) + � (�� )�� + � (�� )���
′ ′′

�′′ (�� )��� = �(��+� ) − �(�� ) − �′ (�� )��


� ′′ ( ) � ′( )

∗ � � � �� = � (� �+� ) − � (� � ) − � � � �� ∗
��� ���

�(��+� ) − �(�� ) � (�� )
�′′ (�� ) = − → ��. �
��� �
NUMERICAL DIFFERENTIATION: FORWARD DIFFERENCE
• Substitute eq. 2 to eq.1 to get the High Accuracy Formula for the First Derivative Approximation for Forward
Difference.
′( )
�(��+� ) − �(�� ) �
� �� = − �′′ (�� ) → ��. �
� �

�(��+� ) − �(�� ) � (�� )
�′′ (�� ) = − → ��. �
��� �
′( )
�(��+� ) − �(�� ) �(��+� ) − �(�� ) �′ (�� ) �
� �� = − −
� ��� � �

�(��+� ) − �(�� ) −�(��+� ) + �(�� ) � (�� )
�′ (�� ) = + +
� �� �
′( ) ( ) ( ) ( ) (
� � � � � �+� − � � � −� � �+� + � �� )
�′ (�� ) − = +
� � ��
′( ) ( ) ( )
′( )
� �� � ��+� − � �� −� ��+� ) + �(�� )
(
� ∗ � �� − = + ∗�
� � ��
��(��+� ) − ��(�� ) −�(��+� ) + �(�� )
��′ (�� ) − �′ (�� ) = +
� ��
�� (� �+� ) − �� (� � ) − � (� �+� ) + � (�� )
�′ (�� ) =
��

−�(��+� ) + ��(��+� ) − ��(�� )


�′ (�� ) =
��
NUMERICAL DIFFERENTIATION: BACKWARD DIFFERENCE
• Backward Difference. The Taylor series can be expanded “backward” to calculate a previous value on the basis of a
present value. It utilizes the i-1 and i to estimate the derivative.
• Derivation. Using the first order approximation of the Taylor series expansion, we can get the first backward divided
difference
′ ′′
�� ′′′
��
�(��−� ) = �(�� ) − � (�� )� + � (�� ) − � (�� ) +⋯
�! �!
�(��−� ) = �(�� ) − �′ (�� )�
�′ (�� )� = �(�� ) − �(��−� )
� �
∗ �′ (�� )� = �(�� ) − �(��−� ) ∗
� �
′( )
�(�� ) − �(��−� )
� �� =

NUMERICAL DIFFERENTIATION: BACKWARD DIFFERENCE
• Derivation. Now we incorporate the additional terms of the Taylor series to have a High Accuracy Divided Difference
Formulas.
′ ′′
�� ′′′
��
�(��−� ) = �(�� ) − � (�� )� + � (�� ) − � (�� ) +⋯
�! �!
′ ′′
��
�(��−� ) = �(�� ) − � (�� )� + � (�� )
�!
′( ) ′′
��
� �� � = �(�� ) − �(��−� ) + � (�� )
�∗�
� ′( ) ′′
�� �
∗ � �� � = �(�� ) − �(��−� ) + � (�� ) ∗
� � �
�(�� ) − �(��−� ) �
�′ (�� ) = + �′′ (�� ) → ��. �
� �
• With these we can incorporate more points to be substituted. When we add more point, the step size (h) will also increase.
Then we can get the value of the �′′ (�� ) in terms of the function of x.
′ ′′
(��)�
�(��−� ) = �(�� ) − � (�� )�� + � (�� )
�!
′ ′′
���
�(��−� ) = �(�� ) − � (�� )�� + � (�� )
�∗�
�(��−� ) = �(�� ) − � (�� )�� + � (�� )���
′ ′′

�′′ (�� )��� = �(��−� ) − �(�� ) + �′ (�� )��


� ′′ ( ) � ′( )

∗ � � � �� = � (� �−� ) − � (� � ) + � � � �� ∗
��� ���

�(��−� ) − �(�� ) � (�� )
�′′ (�� ) = + → ��. �
��� �
NUMERICAL DIFFERENTIATION: BACKWARD DIFFERENCE
• Substitute eq. 2 to eq.1 to get the High Accuracy Formula for the First Derivative Approximation for Backward
Difference.
′( )
�(�� ) − �(��−� ) �
� �� = + �′′ (�� ) → ��. �
� �

�(��−� ) − �(�� ) � (�� )
�′′ (�� ) = + → ��. �
��� �
′( )
�(�� ) − �(��−� ) �(��−� ) − �(�� ) �′ (�� ) �
� �� = + +
� ��� � �

�(�� ) − �(��−� ) �(��−� ) − �(�� ) � (�� )
�′ (�� ) = + +
� �� �
′( ) ( ) ( ) ( ) (
� � � � � � − � � �−� � � �−� − � �� )
�′ (�� ) − = +
� � ��
′( ) ( ) ( )
′( )
� �� � �� − � ��−� � ��−� ) − �(�� )
(
� ∗ � �� − = + ∗�
� � ��
��(�� ) − ��(��−� ) �(��−� ) − �(�� )
��′ (�� ) − �′ (�� ) = +
� ��
�� (� � ) − �� (� �−� ) + � (� �−� ) − � (�� )
�′ (�� ) =
��

��(�� ) − ��(��−� ) + �(��−� )


�′ (�� ) =
��
NUMERICAL DIFFERENTIATION: CENTRAL DIFFERENCE
• Central Difference. The difference between the forward Taylor series and backward Taylor series. It utilizes the i-1 and i+1
to estimate the derivative.
• Derivation. Using the difference of first order approximation of the Taylor series expansion, we can get the first
central divided difference
′( ′′ (
�� ′′′
�� ′ ′′
�� ′′′
��
�(��+� ) − �(��−� ) = �(�� ) + � �� )� + � �� ) + � (�� ) + ⋯ − �(�� ) − � (�� )� + � (�� ) − � (�� ) +⋯
�! �! �! �!
′( ′′′ (
��
�(��+� ) − �(��−� ) = �� �� )� + �� �� )
�!
�(��+� ) − �(��−� ) = ��′ (�� )�
� �
∗ ��′ (�� )� = �(��+� ) − �(��−� ) ∗
�� ��
�(��+� ) − �(��−� )
�′ (�� ) =
��
NUMERICAL DIFFERENTIATION: CENTRAL DIFFERENCE
• Derivation. Now we incorporate the additional terms of the Taylor series to have a High Accuracy Divided Difference
Formulas.
′( ′′ (
�� ′′′
�� ′ ′′
�� ′′′
��
�(��+� ) − �(��−� ) = �(�� ) + � �� )� + � �� ) + � (�� ) + ⋯ − �(�� ) − � (�� )� + � (�� ) − � (�� ) + ⋯
�! �! �! �!
′( ) ′′′ ( )
��
( ) ( )
� ��+� − � ��−� = �� �� � + �� ��
�!

′( ) ′′
��
�� �� � = �(��+� ) − �(��−� ) − � (�� )
�∗�∗�
� ��� �
∗ ��′ (�� )� = �(��+� ) − �(��−� ) − �′′ (�� ) ∗
�� � ��

�(��+� ) − �(��−� ) �
�′ (�� ) = − �′′′ (�� ) → ��. �
�� �
• With these we can incorporate more points to be substituted. When we add more point, the step size (h) will also increase.
Then we can get the value of the �′′′ (�� ) in terms of the function of x.
′( ′′ (
(��)� ′′′
(��)� ′ ′′
(��)� ′′′
(��)�
�(��+� ) − �(��−� ) = �(�� ) + � �� )�� + � �� ) + � (�� ) + ⋯ − �(�� ) − � (�� )�� + � (�� ) − � (�� ) +⋯
�! �! �! �!
(��)�
�(��+� ) − �(��−� ) = ��′ (�� )�� + ��′′′ (�� )
�∗�∗�
′ ′′′
���
�(��+� ) − �(��−� ) = � (�� )�� + � (�� )


��
�′′′ (�� ) = �(��+� ) − �(��−� ) − �′ (�� )��


� ′′′ ( )
�� ′( )

∗ � �� = �(��+� ) − �(��−� ) − � �� �� ∗
��� � ���
′′′ ( )
��(��+� ) − ��(��−� ) ��′ (�� )
� �� = − → ��. �
��� ���
NUMERICAL DIFFERENTIATION: CENTRAL DIFFERENCE
• Substitute eq. 2 to eq.1 to get the High Accuracy Formula for the First Derivative Approximation for Central
Difference.
′( )
�(��+� ) − �(��−� ) ′′′ ( )
��
� �� = − � �� → ��. �
�� �
′′′ ( )
��(��+� ) − ��(��−� ) ��′ (�� )
� �� = − → ��. �
��� ���
′( )
�(��+� ) − �(��−� ) ��(��+� ) − ��(��−� ) ��′ (�� ) ��
� �� = − −
�� ��� ��� �

′( )
�(��+� ) − �(��−� ) −�(��+� ) + �(��−� ) � (�� )
� �� = + +
�� ��� �
′( )
� �� �(��+� ) − �(��−� ) −�(��+� ) + �(��−� )
�′ (�� ) − = +
� �� ���
′( )
� �� �(��+� ) − �(��−� ) −�(��+� ) + �(��−� )
� ∗ �′ (�� ) − = + ∗�
� �� ���
′( ) ′( )
��(��+� ) − ��(��−� ) −�(��+� ) + �(��−� )
�� �� − � �� = +
� ��
��(��+� ) − ��(��−� ) − �(��+� ) + �(��−� )
��′ (�� ) =
��
� ��(��+� ) − ��(��−� ) − �(��+� ) + �(��−� ) �
∗ ��′ (�� ) = ∗
� �� �

−�(��+� ) + ��(��+� ) − ��(��−� ) + �(��−� )


�′ (�� ) =
���
NUMERICAL DIFFERENTIATION: SUMMARY
• Forward finite-divided-difference formulas: two versions are presented for each derivative. The
latter version incorporates more terms of the Taylor series expansion and is, consequently, more
accurate.
NUMERICAL DIFFERENTIATION: SUMMARY
• Backward finite-divided-difference formulas: two versions are presented for each derivative.
The latter version incorporates more terms of the Taylor series expansion and is, consequently,
more accurate.
NUMERICAL DIFFERENTIATION: SUMMARY
• Central finite-divided-difference formulas: two versions are presented for each derivative. The
latter version incorporates more terms of the Taylor series expansion and is, consequently, more
accurate.
NUMERICAL DIFFERENTIATION: EXAMPLE
1. Use forward, backward and a centered difference approximation to estimate the first derivative of
�(�) =− �. ��� − �. ���� − �. ��� − �. ��� + �. � at x=0.5 using a step size h=0.25.
SOLUTION:
a. Note that the derivative can be calculated directly as
�’(�) =− �. ��� − �. ���� − �. �� − �. ��
and can be used to compute the true value
�’(�. �) =− �. �(�. �)� − �. ��(�. �)� − �. �(�. �) − �. �� =− �. ����
b. For h=0.25, the function can be employed to determine
�� = �. �
��+� = �. � + �. �� = �. ��
��−� = �. � − �. �� = �. ��
c. Then, find the values of � or �(�) using the given.
�(�� ) = �(�. �) =− �. �(�. �)� − �. ��(�. �)� − �. �(�. �)� − �. ��(�. �) + �. � = �. ����
�(��+� ) = �(�. ��) =− �. �(�. ��)� − �. ��(�. ��)� − �. �(�. ��)� − �. ��(�. ��) + �. � = �. ����
�(��−� ) = �(�. ��) =− �. �(�. ��)� − �. ��(�. ��)� − �. �(�. ��)� − �. ��(�. ��) + �. � = �. ����
d. Calculate the forward difference and its true percent error.
′( )
�(��+� ) − �(�� ) �. ���� − �. ����
� �� = = �′ (�. �) = =− �. ����
� �. ��
NUMERICAL DIFFERENTIATION: EXAMPLE
1. Use forward, backward and a centered difference approximation to estimate the first derivative of
�(�) =− �. ��� − �. ���� − �. ��� − �. ��� + �. � at x=0.5 using a step size h=0.25.

SOLUTION:
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = ��. ����%
�� −�. ����
e. Calculate the backward difference and its true percent error.
′( )
�(�� ) − �(��−� ) ′(
�. ���� − �. ����
� �� = = � �. �) = =− �. ����
� �. ��
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = ��. ����%
�� −�. ����
f. Calculate the central difference and its true percent error.
′( )
�(��+� ) − �(��−� ) �. ���� − �. ����
� �� = = �′ (�. �) = =− �. ����
�� �(�. ��)
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = �. ����%
�� −�. ����
g. Conclusion: The centered difference approximation is more accurate than forward or backward
differences having least error.
NUMERICAL DIFFERENTIATION: EXAMPLE (using high accuracy formula)
1. Use forward, backward and a centered difference approximation to estimate the first derivative of �(�) =−
�. ��� − �. ���� − �. ��� − �. ��� + �. � at x=0.5 using a step size h=0.25.
SOLUTION:
a. Note that the derivative can be calculated directly as
�’(�) =− �. ��� − �. ���� − �. �� − �. ��
and can be used to compute the true value
�’(�. �) =− �. �(�. �)� − �. ��(�. �)� − �. �(�. �) − �. �� =− �. ����
b. For h=0.25, the function can be employed to determine the following including the additioinal points
�� = �. �
��+� = �. � + �. �� = �. ��
��−� = �. � − �. �� = �. ��
��+� = �. � + �(�. ��) = �
��−� = �. � − �(�. ��) = �
c. Then, find the values of � or �(�) using the given.
�(�� ) = �(�. �) =− �. �(�. �)� − �. ��(�. �)� − �. �(�. �)� − �. ��(�. �) + �. � = �. ����
�(��+� ) = �(�. ��) =− �. �(�. ��)� − �. ��(�. ��)� − �. �(�. ��)� − �. ��(�. ��) + �. � = �. ����
�(��−� ) = �(�. ��) =− �. �(�. ��)� − �. ��(�. ��)� − �. �(�. ��)� − �. ��(�. ��) + �. � = �. ����
�(��+� ) = �(�) =− �. �(�)� − �. ��(�)� − �. �(�)� − �. ��(�) + �. � = �. ����
�(��−� ) = �(�) =− �. �(�)� − �. ��(�)� − �. �(�)� − �. ��(�) + �. � = �. ����
NUMERICAL DIFFERENTIATION: EXAMPLE (using high accuracy formula)
1. Use forward, backward and a centered difference approximation to estimate the first derivative of �(�) =− �. ��� −
�. ���� − �. ��� − �. ��� + �. � at x=0.5 using a step size h=0.25.
SOLUTION:
d. Calculate the forward difference and its true percent error.
−�(��+� ) + ��(��+� ) − ��(�� ) −�. ���� + �(�. ����) − �(�. ����)
�′ (�� ) = = �′ (�. �) = =− �. ����
�� �(�. ��)
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = �. ����%
�� −�. ����
e. Calculate the backward difference and its true percent error.
��(�� ) − ��(��−� ) + �(��−� ) �(�. ����) − �(�. ����) + �. ����
�′ (�� ) = = �′ (�. �) = =− �. ����
�� �(�. ��)
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = �. ����%
�� −�. ����
f. Calculate the central difference and its true percent error.
′( )
−�(��+� ) + ��(��+� ) − ��(��−� ) + �(��−� )
� �� =
���
−�. ���� + �(�. ����) − �(�. ����) + �. ����
�′ (�. �) = =− �. ����
��(�. ��)
�� − �� −�. ���� − (−�. ����)
�� = ∗ ��� = ∗ ��� = �%
�� −�. ����
g. Conclusion: All of the results were lessen the errors using the high accuracy formulas and the centered difference
approximation have the same results of the true value having no error..
NUMERICAL DIFFERENTIATION: COMPARISON
Use forward, backward and a centered difference approximation to estimate the first derivative of �(�) =− �. ��� −
�. ���� − �. ��� − �. ��� + �. � at x=0.5 using a step size h=0.25.

• High accuracy formula has more accurate results due to more points was considered in solving the numerical
derivative of the function.
• Either basic and high accuracy formula, the central difference approximation has the most accurate results.

TRUE VALUE USING ONLY 1ST TERM OF TAYLOR USING ADDITIONAL TERMS OF TAYLOR
=-0.9125 (basic formula) (high accuracy formula)

TRUE PERCENT TRUE PERCENT


FIRST DERIVATIVE FIRST DERIVATIVE
ERROR ERROR

FORWARD
-1.1548 26.5534% -0.8596 5.7973%
DIFFERENCE

BACKWARD
-0.7140 21.7534% -0.8780 3.7808%
DIFFRENCE

CENTRAL
-0.9344 2.4000% -0.9125 0%
DIFFERENCE
NUMERICAL INTEGRATION
• Numerical Integration is a technique used in analysis to approximate the definite integral of a function
over a specified interval. It becomes necessary when standard mathematical methods cannot evaluate
the integral.
• To integrate means “to bring together, as parts, into a whole; to unite; to indicate the total
amount”.
• Mathematically, integration is represented by

�= �(�)��

which stands for the integral of the function f(x) with respect to the independent variable x,
evaluated between the limits x=a to x=b. The function f(x) in the equation is referred to as the
integrand.
• The figure represents a graphical manifestation of the concept.
For functions lying above the x-axis, the integral expressed by
our equation corresponds to the area under the curve of f(x)
between x=a and b.
NUMERICAL INTEGRATION: TRAPEZOIDAL RULE
• A rule that evaluates the area under the curves by dividing the total area into smaller trapezoids rather than
using rectangles.This integration works by approximating the region under the graph of a function as a
trapezoid, and it calculates the area.
• One way to improve the accuracy of the trapezoidal rule is to divide the integration interval from a to b into a
number of segments and apply the method to each segment (Fig. 21.7).
• The areas of individual segments can then be added to yield the integral for the entire interval. The resulting
equations are called multiple-application, or composite, integration formulas. Figure 21.8 shows the
general format and nomenclature we will use to characterize multiple-application integrals. There are n+1
�−�
equally spaced base points (x0, x1, x2, . . . , xn). Consequently, there are n segments of equal width: � =

NUMERICAL INTEGRATION: TRAPEZOIDAL RULE
• The trapezoidal rule is the first of the Newton-Cotes closed integration formulas. It corresponds to the case
where the polynomial is first order:
� �
�= �(�)�� ≅ �� (�)��
� �

• Previously, from our topics; straight line can be expressed as,


�(�) − �(�)
�� (�) = �(�) + (� − �)
�−�
• Then we should get the intregral;

�(�) − �(�)
�≅ (�(�) + (� − �))��
� � − �

• The results is the trapezoidal rule:


�(�) + �(�)
�≅�

• If a and b are designated as x0 and xn, respectively, the total integral can be represented as
�� �� ��
�= �(�)�� + �(�)�� + . . . �(�)��
�� �� ��−�
NUMERICAL INTEGRATION: TRAPEZOIDAL RULE
• Substituting the trapezoidal rule for each integral yields
�(�� ) + �(�� ) �(�� ) + �(�� ) �(��−� ) + �(�� )
�=� +� + ... + �
� � �
or, grouping terms,
� �−�
� = �(�� ) + � �(�� ) + �(�� )
� �=�
• Substitute the value of h,
�−� �−�

�= �(�� ) + � �(�� ) + �(�� )
� �=�
• We get the general formula of the trapezoidal rule:
�−�
�(�� ) + � �=�
�(�� ) + �(�� )
� = (� − �)
��
• We can get Approximation Error using the formula:
(� − �)�
�� =− (�’’)
����
where,


�’’(�)��
�’’ =
�−�
NUMERICAL INTEGRATION: TRAPEZOIDAL RULE (example)
Use the two-segment trapezoidal rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� +
����� from 0 to 0.8. Calculate also the error.
SOLUTION:
a. Note that the integral can be calculated directly as

�= �(�)��

and can be used to compute the true value
�.�
�= (�. � + ��� − ����� + ����� − ����� + ����� ) �� = �. ����

b. From the problem our n = 2, x0 = 0 = a and xn = 0.8 = b, calculate the value of h
� − � �. � − �
�= = = �. �
� �
c. Then, find the values of � using the given and calculate the corresponding � or �(�) values.
�� = �
�(�� ) = �. � + ��(�) − ���(�)� + ���(�)� − ���(�)� + ���(�)� = �. ����
�� = � + �. � = �. �
�(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
�� = �. � + �. � = �. �
�(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
NUMERICAL INTEGRATION: TRAPEZOIDAL RULE (example)
Use the two-segment trapezoidal rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� +
����� from 0 to 0.8. Calculate also the error.
SOLUTION:
d. Substitute the computed values and estimate the integral using the formula.
�(�� ) + � �−�
�=�
�(�� ) + �(�� ) �(�� ) + ��(�� ) + �(�� )
� = (� − �) = (�. � − �)
�� �(�)
�. ���� + �(�. ����) + �. ����
� = (�. �) = �. ����

e. Calculate the percent true error.
�� = �� − �� = �. ���� − �. ���� = �. ����
�� − �� �. ����
�� = ∗ ��� = ∗ ��� = ��. ��%
�� �. ����
e. In some actual situation, we cannot get the the true value, now, let’s solve the approximation error.
(� − �)�
�� =− (�’’)
����
� �.� � � � �. �

�’’(�)�� �
(−��� + ����� − ������� + ������ ) �� −���� + ����� − ����� + ����� �
�’’ = = =
�−� �. � − � �. �
(−���(�. �) + ����(�. �)� − ����(�. �)� + ����(�. �)� ) − (−���(�) + ����(�)� − ����(�)� + ����(�)� )
=− ��
�. �
(�. � − �)�
�� =− (−��) = �. ����
��(�)�
NUMERICAL INTEGRATION: SIMPSONS RULE
• Another way to obtain a more accurate estimate of an integral is to use higher-order polynomials to connect
the points.
• For example, if there is an extra point midway between f(a) and f(b), the three points can be connected with
a parabola (Fig. 21.10a).
• If there are two points equally spaced between f(a) and f(b), the four points can be connected with a third-
order polynomial(Fig. 21.10b).
• The formulas that result from taking the integrals under these polynomials are called Simpson’s rules.
NUMERICAL INTEGRATION: 1/3 SIMPSONS RULE
• Simpson’s 1/3 rule results when a second-order interpolating polynomial:
� �
�= �(�)�� ≅ �� (�)��
� �

• If a and b are designated as x0 and x2 and �� (�) is represented by a second-order Lagrange polynomial ,
(� − �� )(� − �� ) (� − �� )(� − �� ) (� − �� )(� − �� )
�� (�) = �(�� ) + �(�� ) + �(�� )
(�� − �� )(�� − �� ) (�� − �� )(�� − �� ) (�� − �� )(�� − �� )
• The integral becomes;
��
(� − �� )(� − �� ) (� − �� )(� − �� ) (� − �� )(� − �� )
�≅ �(�� ) + �(�� ) + �(�� ) ��
�� (� � − � � )(� � − � � ) (� � − � � )(� � − � � ) (� � − � � )(� � − � � )

• The results is the 1/3 simpsons rule:



�≅ �(�� ) + ��(�� ) + �(�� )

• If a and b are designated as x0 and xn, respectively, the total integral can be represented as
�� �� ��
�= �(�)�� + �(�)�� + . . . �(�)��
�� �� ��−�
NUMERICAL INTEGRATION: 1/3 SIMPSONS RULE
• Substituting the 1/3 simpsons rule for each integral yields
� � �
� = �(�� ) + ��(�� ) + �(�� ) + �(�� ) + ��(�� ) + �(�� ) + . . . + �(��−� ) + ��(��−� ) + �(�� )
� � �
or, grouping terms,
� �−� �−�
� = �(�� ) + � �(�� ) + � �(�� ) + �(�� )
� �=�,�,�,... �=�,�,�,...
• Substitute the value of h,
�−�
�−� �−�
�= � �(�� ) + � �(�� ) + � �(�� ) + �(�� )
� �=�,�,�,... �=�,�,�,...
• We get the general formula of the 1/3 simpsons rule: (note that for this rule, it can only be use if n must be even)
�(�� ) + � �−�
�=�,�,�
�(� � ) + � �−�
�=�,�,�
�(�� ) + �(�� )
� = (� − �)
��
• We can get Approximation Error using the formula:
(� − �)�
�� =− (�’’’’)
�����
where,


�’’’’(�)��
�’’’’ =
�−�
NUMERICAL INTEGRATION: 1/3 SIMPSONS RULE (example)
Use the four-segment 1/3 simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� −
����� + ����� from 0 to 0.8. Calculate the error.
SOLUTION:
a. Note that the integral can be calculated directly as

�= �(�)��

and can be used to compute the true value
�.�
�= (�. � + ��� − ����� + ����� − ����� + ����� ) �� = �. ����

b. From the problem our n = 4, x0 = 0 = a and xn = 0.8 = b, calculate the value of h
� − � �. � − �
�= = = �. �
� �
c. Then, find the values of � using the given and calculate the corresponding � or �(�) values.
�� = �; �(�� ) = �. � + ��(�) − ���(�)� + ���(�)� − ���(�)� + ���(�)� = �. ����
�� = � + �(�. �) = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
�� = � + �(�. �) = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
�� = � + �(�. �) = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
�� = � + �(�. �) = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
NUMERICAL INTEGRATION: 1/3 SIMPSONS RULE (example)
Use the four-segment 1/3 simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� −
����� + ����� from 0 to 0.8. Calculate the error.
SOLUTION:
d. Substitute the computed values and estimate the integral using the formula.
�−� �−�
�(�� ) + � �=�,�,�
�(�� ) +� �=�,�,�
�(�� ) + �(�� )
� = (� − �)
��
�(�� ) + � �(�� ) + �(�� ) + ��(�� ) + �(�� )
� = (�. � − �)
�(�)
�. ���� + �(�. ���� + �. ����) + �(�. ����) + �. ����
� = (�. �) = �. ����
��
e. Calculate the percent true error.
�� = �� − �� = �. ���� − �. ���� = �. ����
�� �. ����
�� = ∗ ��� = ∗ ��� = �. ����%
�� �. ����
e. In some actual situation, we cannot get the the true value, now, let’s solve the approximation error.
� �.�
(� − �)� �
�’’’’(�)�� �
(−����� + ������) ��
�� =− (�’’’’); ����� �’’’’ = =
����� �−� �. � − �
�. �
−������ + ������� (−�����(�. �) + �����(�. �)� ) − (−�����(�) + �����(�)� )
= � = =− ����
�. � �. �
(�. � − �)�
�� =− (−����) = �. ����
���(�)�
NUMERICAL INTEGRATION: 3/8 SIMPSONS RULE
• Simpson’s 3/8 rule results when a third-order interpolating polynomial:
� �
�= �(�)�� ≅ �� (�)��
� �
• If a and b are designated as x0 and x3 and �� (�) is represented by a third-order Lagrange polynomial ,
(� − �� )(� − �� )(� − �� ) (� − �� )(� − �� )(� − �� ) (� − �� )(� − �� )(� − �� )
�� (�) = �(�� ) + �(�� ) + �(�� )
(�� − �� )(�� − �� )(�� − �� ) (�� − �� )(�� − �� )(�� − �� ) (�� − �� )(�� − �� )(�� − �� )
(� − �� )(� − �� )(� − �� )
+ �(�� )
(�� − �� )(�� − �� )(�� − �� )
• The integral becomes;
��
(� − �� )(� − �� )(� − �� ) (� − �� )(� − �� )(� − �� ) (� − �� )(� − �� )(� − �� ) (� − �� )(� − �� )(� − �� )
�≅ �(�� ) + �(�� ) + �(�� ) + �(�� ) ��
�� (�� − �� )(�� − �� )(�� − �� ) (�� − �� )(�� − �� )(�� − �� ) (�� − �� )(�� − �� )(�� − �� ) (�� − �� )(�� − �� )(�� − �� )

• The results is the 3/8 simpsons rule:


��
�≅ �(�� ) + ��(�� ) + ��(�� ) + �(�� )

• If a and b are designated as x0 and xn, respectively, the total integral can be represented as
�� �� ��
�= �(�)�� + �(�)�� + . . . �(�)��
�� �� ��−�
NUMERICAL INTEGRATION: 3/8 SIMPSONS RULE
• Substituting the 3/8 simpsons rule for each integral yields
�� �� ��
�= �(�� ) + ��(�� ) + ��(�� ) + �(�� ) + �(�� ) + ��(�� ) + ��(�� ) + �(�� ) + . . . + �(��−� ) + ��(��−� ) + ��(��−� ) + �(�� )
� � �
or, grouping terms,
�� �−� �−�
�= �(�� ) + � �(�� ) − �(�� ) + �(�� )
� �=� �=�,�,�,...
• Substitute the value of h,
�−�
� �−� �−�
�= � �(�� ) + � �(�� ) − �(�� ) + �(�� )
� �=� �=�,�,�,...
• We get the general formula of the 3/8 simpsons rule: (note that for this rule, it can only be use if n must be a
multiple of 3)
�−� �−�
�(�� ) + � �=�
�(�� ) − �=�,�,�,...
�(�� ) + �(�� )
� = �(� − �)
��
• We can get Approximation Error using the formula:

�� =− (�� )(�’’’’)
��
where,


�’’’’(�)��
�’’’’ =
�−�
NUMERICAL INTEGRATION: 3/8 SIMPSONS RULE (example)
Use the three-segment 3/8 simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� −
����� + ����� from 0 to 0.8. Calculate the error.
SOLUTION:
a. Note that the integral can be calculated directly as

�= �(�)��

and can be used to compute the true value
�.�
�= (�. � + ��� − ����� + ����� − ����� + ����� ) �� = �. ����

b. From the problem our n = 3, x0 = 0 = a and xn = 0.8 = b, calculate the value of h
� − � �. � − � �
�= = =
� � ��
c. Then, find the values of � using the given and calculate the corresponding � or �(�) values.
�� = �; �(�� ) = �. � + ��(�) − ���(�)� + ���(�)� − ���(�)� + ���(�)� = �. ����
�� = � + � � �� = �. ����; �(�� ) = �. � + ��(�. ����) − ���(�. ����)� + ���(�. ����)� − ���(�. ����)� + ���(�. ����)� = �. ����
�� = � + � � �� = �. ����; �(�� ) = �. � + ��(�. ����) − ���(�. ����)� + ���(�. ����)� − ���(�. ����)� + ���(�. ����)� = �. ����
�� = � + � � �� = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
NUMERICAL INTEGRATION: 3/8 SIMPSONS RULE (example)
Use the three-segment 3/8 simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� −
����� + ����� from 0 to 0.8. Calculate the error.
SOLUTION:
d. Substitute the computed values and estimate the integral using the formula.
�−� �−�
�(�� ) + � �=�
�(�� ) − �=�,�,�,...
�(�� ) + �(�� )
� = �(� − �)
��
�(�� ) + � �(�� ) + �(�� ) − � + �(�� )
� = �(�. � − �)
�(�)
�. ���� + �(�. ���� + �. ����) − � + �. ����
� = �(�. �) = �. ����
��
e. Calculate the percent true error.
�� = �� − �� = �. ���� − �. ���� = �. ����
�� �. ����
�� = ∗ ��� = ∗ ��� = �. ����%
�� �. ����
e. In some actual situation, we cannot get the the true value, now, let’s solve the approximation error.
� �.�
� �’’’’(�)�� (−����� + ������) ��
�� =− (�� )(�’’’’); ����� �’’’’ = � = �
�� �−� �. � − �
�. �
−������ + ������� (−�����(�. �) + �����(�. �)� ) − (−�����(�) + �����(�)� )
= � = =− ����
�. � �. �
� � �
�� =− (−����) = �. ����
�� ��
NUMERICAL INTEGRATION: COMBINED SIMPSONS RULE
• If the number of segments is not even nor multiple of 3 we can use the combination of 1/3 and 3/8
simpson’s rule.
• Example. If n=5 and the limits are designated as x 0 and x 5 , the x 0 , x 1 , x 2 sub intervals can use the 1/3
simpsons rule since it has 3 points and can create 2 segments, the x2, x3, x4, x5 sub intervals can use the 3/8
simpsons rule since it has 4 points and can create 3 segments.
SAMPLE PROBLEM:
Use the five-segment simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� +
����� from 0 to 0.8. Calculate the error.
SOLUTION:
a. Note that the integral can be calculated directly as

�= �(�)��

and can be used to compute the true value
�.�
�= (�. � + ��� − ����� + ����� − ����� + ����� ) �� = �. ����

b. From the problem our n = 5, x0 = 0 = a and xn = 0.8 = b, calculate the value of h
� − � �. � − �
�= = = �. ��
� �
NUMERICAL INTEGRATION: COMBINED SIMPSONS RULE
SAMPLE PROBLEM:
Use the five-segment simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� + ����� from 0 to
0.8. Calculate the error.
SOLUTION:
c. Then, find the values of � using the given and calculate the corresponding � or �(�) values.
�� = �; �(�� ) = �. � + ��(�) − ���(�)� + ���(�)� − ���(�)� + ���(�)� = �. ����
�� = � + �(�. ��) = �. ��; �(�� ) = �. � + ��(�. ��) − ���(�. ��)� + ���(�. ��)� − ���(�. ��)� + ���(�. ��)� = �. ����
�� = � + �(�. ��) = �. ��; �(�� ) = �. � + ��(�. ��) − ���(�. ��)� + ���(�. ��)� − ���(�. ��)� + ���(�. ��)� = �. ����
�� = � + �(�. ��) = �. ��; �(�� ) = �. � + ��(�. ��) − ���(�. ��)� + ���(�. ��)� − ���(�. ��)� + ���(�. ��)� = �. ����
�� = � + �(�. ��) = �. ��; �(�� ) = �. � + ��(�. ��) − ���(�. ��)� + ���(�. ��)� − ���(�. ��)� + ���(�. ��)� = �. ����
�� = � + �(�. ��) = �. �; �(�� ) = �. � + ��(�. �) − ���(�. �)� + ���(�. �)� − ���(�. �)� + ���(�. �)� = �. ����
d. It is observed that the number of segments, n, is not even number so we cannot use the 1/3 simpsons rule alone. Also, it is not
a multiple of 3 so we cannot use the 3/8 simpsons rule alone. But we can used both to estimate. The first 2 segments can use
the 1/3 simpsons since 2 is an even number. The last 3 segments can use the 3/8 simpsons since 3 is a multiple of 3.
� ≅ ��/� + ��/�
�� ��
�= �(�)�� + �(�)��
�� ��
�−� �−�
�(�� ) + � �=�,�,�
�(�� ) +� �=�,�,�
�(�� ) + �(�� )
� = (� − �)
��
�(�� ) + � �−�
�=�
�(� � ) − �−�
�=�,�,�,...
�(�� ) + �(�� )
+ �(� − �)
��
NUMERICAL INTEGRATION: COMBINED SIMPSONS RULE
SAMPLE PROBLEM:
Use the five-segment simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� + ����� from 0 to
0.8. Calculate the error.
SOLUTION:
e. Substitute the computed values and estimate the integral using 1/3 simpsons rule on the first 2 segments.
�−� �−�
�(�� ) + � �=�,�,�
�(�� ) +� �=�,�,�
�(�� ) + �(�� )
� = (� − �)
��
�(�� ) + � �(�� ) + � + �(�� )
� = (�. �� − �)
�(�)
�. ���� + �(�. ����) + � + �. ����
� = (�. ��) = �. ����

f. Substitute the computed values and estimate the integral using 3/8 simpsons rule on the last 3 segments.
�� , �(�� ) → � = �
�� , �(�� ) → � = �
�� , �(�� ) → � = �
�� , �(�� ) → � = �
�−� �−�
�(�� ) + � �=�
�(�� ) − �=�,�,�,...
�(�� ) + �(�� )
� = �(� − �)
��
�(�� ) + � �(�� ) + �(�� ) − � + �(�� )
� = �(�. � − �. ��)
�(�)
�. ���� + �(�. ���� + �. ����) − � + �. ����
� = �(�. ��) = �. ����
��
NUMERICAL INTEGRATION: COMBINED SIMPSONS RULE
SAMPLE PROBLEM:
Use the five-segment simpsons rule to estimate the integral of �(�) = �. � + ��� − ����� + ����� − ����� +
����� from 0 to 0.8. Calculate the error.
SOLUTION:
g. Add the computed values to estimate the integral.
�� ��
�= �(�)�� + �(�)��
�� ��
� = �. ���� + �. ���� = �. ����
h. Calculate the error.
�� = �� − �� = �. ���� − �. ���� =− �. ����
�� −�. ����
�� = ∗ ��� = ∗ ��� = �. ����%
�� �. ����
NUMERICAL INTEGRATION: BOARD EXERCISES
2point and 3point estimate

You might also like