Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

NUMERICAL ANALYSIS

University of Babylon / College of Engineering / Mechanical Eng. Dept.


Lecturer: Dr. Rafel Hekmat Class: 3rd B.Sc.

NUMERICAL DIFFERENTIATION & INTEGRATION

NUMERICAL INTEGRATION
We will discuss the trapezoidal rule that computes a function f(x) with a set of linear
functions, and Simpson’s rule that computes a function f(x) with a set of quadratic functions.
1-Trapezoidal Rule
Consider the function y=f(x) for the interval a ≤ x ≤ b, shown in Figure

1
The approximation error is a sum of the individual errors, i.e.,

Example:
Use the 2-segment trapezoidal rule to numerically integrate f(x) = 0.2 + 25x + 3x2 ,
from a = 0 to b = 2.
Solution: n = 2, h = (a- b) / n = (2 - 0) / 2 = 1.
f(0) = 0.2, f(1) = 28.2, and f(2) = 62.2.

The relative error is

Approximated error
f (x) = 0.2+25x+3x2
f `(x) = 25+6x
f `` (x) = 6
2
∫ 6 𝑑𝑥
̅ = 0
𝑓" =6
2−0

2
(2 − 0)3
∈t = ∗6=1
12 ∗ 22
EXAMPLE: Use the two-segment trapezoidal rule to estimate the integral of
f(x) = 0.2 + 25x − 200x2 + 675x3 − 900x4 + 400x5 from a = 0 to b = 0.8. Estimate the errors. If
you know that the correct value for the integral is 1.640533.

H.W.
Using the trapezoidal rule with n=4 , estimate the value of the definite integral

Compare with the exact value, and compute the percent error.
Ans. I=2.34375

H.W.

3
H.W
Integrate the following function analytically and using the trapezoidal rule, with n =4

Use the analytical solution to compute true percent relative errors to evaluate the accuracy of
the trapezoidal approximations.

2- Simpson’s 1/3 Rule


Just as with the trapezoidal rule, Simpson’s rule can be improved by dividing the
integration interval into a number of segments of equal width as shown in figure below

Error in the Multiple Segment Simpson’s 1/3rd Rule


(b  a ) 5 ( 4 )
Et   f
90 n 4
n
2
 f ( i )
( 4)
( 4)
f  i 1

4
Example:
with n = 4 to estimate the integral of f(x) = 0.2 + 25x − 200x2 + 675x3 − 900x4 + 400x5
from a = 0 to b = 0.8. If you know that the exact integral is 1.640533.

Ans. I=1.623467
Et = 1.640533 − 1.623467 = 0.017067
Example:
Use 4-segment Simpson’s 1/3 rule to approximate the distance covered by a rocket in
meters from t = 8 s to t= 30 s as given by

a) Use four segment Simpson’s 1/3rd Rule to find the probability.


b) Find the true error, Et for part (a).
Solution: Using n segment Simpson’s 1/3 rule,

n = 4, a = 8, b = 30, h=5.5

5
6
INTEGRATION WITH UNEQUAL SEGMENTS
To this point, all formulas for numerical integration have been based on equally spaced data
points. In practice, there are many situations where this assumption does not hold and we must
deal with unequal-sized segments. For example, experimentally derived data is often of this
type. For these cases, one method is to apply the trapezoidal rule to each segment and sum the
results:

EXAMPLE:
Use the data in table below to determine the integral for this data. Knowing that the correct
answer is 1.640533.

MULTIPLE INTEGRALS
Recall from calculus that such integrals can be computed as iterated integrals

A numerical double integral would be based on the same idea. First, methods like the multiple-
segment trapezoidal or Simpson’s rule would be applied in the first dimension with each value
7
of the second dimension held constant. Then the method would be applied to integrate the
second dimension. The approach is illustrated in the following examples.

EXAMPLE:
Suppose that the temperature of a rectangular heated plate is described by the following
function: T (x, y) = 2xy + 2x − x2 − 2y2 + 72 If the plate is 8-m long (x dimension) and 6-m
wide (y dimension), compute the average temperature.

EXAMPLE:
Evaluate
2.6 4.6
1
𝐼 =∫ ∫ 𝑑𝑥𝑑𝑦
𝑥𝑦
2 4

Take dx = 0.2 in x-direction, dy = 0.3 in y-direction. Use Trapezoidal rule in x- direction and
Simpson’s 1/3 rule in y-direction.
𝟏
Calculate the value of 𝒇(𝒙, 𝒚) =
𝒙𝒚

x
y

Applying trapezoidal rule in x-direction


For y=2 : I=0.2/2(0.125+2*0.1191+2*0.1136+0.1087) = 0.0699
For y=2.3 : I=0.2/2(0.1087+2*0.1035+2*0.0988+0.0945)= 0.0608
8
For y=2.6 : I=0.2/2(0.0962+2*0.0916+2*0.0874+0.0836)= 0.0538
We can put in the table

y 2 2.3 2.6

f(y) 0.0699 0.0608 0.0538

Applying Simpson’s 1/3 rule in y-direction


I=0.3/3(0.0699+4*0.0608+0.0538)= 0.0367

You might also like