numerical differentiation & integration

9
1 NUMERICAL ANALYSIS University of Babylon / College of Engineering / Mechanical Eng. Dept. Lecturer: Dr. Rafel Hekmat Class: 3 rd 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

Upload: khangminh22

Post on 04-Feb-2023

0 views

Category:

Documents


0 download

TRANSCRIPT

1

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

2

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

𝑓"̅ =∫ 6 𝑑𝑥

2

0

2 − 0= 6

3

∈t=(2 − 0)

12 ∗ 22

3

∗ 6 = 1

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.

4

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

)4(

4

5

90

)(f

n

abE

t

n

f

f

n

ii

2

1

)4(

)4()(

5

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

6

7

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

8

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

𝐼 = ∫ ∫1

𝑥𝑦𝑑𝑥𝑑𝑦

4.6

4

2.6

2

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 𝒇(𝒙, 𝒚) =𝟏

𝒙𝒚

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

x

y

9

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

2.6 2.3 2 y

0.0538 0.0608 0.0699 f(y)

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

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