Numerical Integration

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

NUMERICAL INTEGRATION: Trapezoidal rule

Numerical integration simply means the numerical evaluation of


𝒃
integrals 𝑰 = ∫𝒂 𝒇(𝒙)𝒅𝒙
Where a and b are given and f(x) is a function given analytically
by a formula or empirically by a table of values. We can represent
geometrically, I as the area under the curve of f(x) between a and
b as shown

Fig 1. Graphical depiction of the trapezoidal rule.

Geometrically, the trapezoidal rule is equivalent to approximating


the area of the trapezoid under the straight line connecting f (a)
and f (b) in fig 1. Recall from geometry that the formula for
computing the area of a trapezoid is the height times the average
of the bases (Fig2a). In our case, the concept is the same but the
trapezoid is on its side (Fig.2b). Therefore, the integral estimate can
be represented as
I ∼= width × average height
(a) The formula for computing the area of a trapezoid: height times
the average of the bases.
(b) For the trapezoidal rule, the concept is the same but the
trapezoid is on its side

or
I ∼= (b − a) × average height
where, for the trapezoidal rule, the average height is the average
of the function values at
the end points, or [ f (a) + f (b)]/2.
Generally;
Trapezoidal rule is given as
𝒙𝟎 +𝒏𝒉
𝒉
𝑰=∫ 𝒇(𝒙)𝒅𝒙 = [(𝒚𝟎 + 𝒚𝒏 ) + 𝟐(𝒚𝟏 + 𝒚𝟐 + ⋯ + 𝒚𝒏−𝟏 )]
𝒙𝟎 𝟐

𝒃
RULES FOR EVALUATING ∫𝒂 𝒇(𝒙)𝒅𝒙 USING
TRAPEZOIDAL RULE OR SIMPSON’S RULE
𝒃
1. Compare the given definite integral, say I, with ∫𝒂 𝒇(𝒙)𝒅𝒙 to
get the values of f(x) and limits a, b,
𝒃−𝒂
2. Compute h= , where n denotes the number of sub-intervals
𝒏
for the problem.
3. Find the values of y=f(x), corresponding to 𝒙𝟎 = 𝒂, 𝒙𝟏 = 𝒂 +
𝒉, 𝒙𝟐 = 𝒙𝟎 + 𝟐𝒉, … . , 𝒙𝒏 = 𝒙𝟎 + 𝒏𝒉 =
𝒃 𝒂𝒏𝒅 𝒅𝒆𝒏𝒐𝒕𝒆 𝒕𝒉𝒆𝒔𝒆 𝒗𝒂𝒍𝒖𝒆𝒔 𝒂𝒔 𝒚𝟎 , 𝒚𝟏 , 𝒚𝟐 , … . . , 𝒚𝒏. .
4. Apply the specified rule to calculate I (either Trapezoidal rule
or Simpson’s rule).
By trapezoidal rule, we have

𝒙𝟎 +𝒏𝒉
𝒉
𝑰=∫ 𝒇(𝒙)𝒅𝒙 = [(𝒚𝟎 + 𝒚𝒏 ) + 𝟐(𝒚𝟏 + 𝒚𝟐 + ⋯ + 𝒚𝒏−𝟏 )]
𝒙𝟎 𝟐

𝟏
Example: Use Trapezoidal Rule to evaluate ∫𝟎 𝒙𝟑 𝒅𝒙 considering 5
subintervals.

𝟏
Sol. Let 𝑰 = ∫𝟎 𝒙𝟑 𝒅𝒙.

h=0.2, f(x) = 𝒙𝟑

Trapezoidal rule is given by


𝒉
𝑰 = [(𝒚𝟎 + 𝒚𝒏 ) + 𝟐(𝒚𝟏 + 𝒚𝟐 + ⋯ + 𝒚𝒏−𝟏 )]
𝟐

Putting the values in the above equation, we have

𝟏
𝑰 = ∫ 𝒙𝟑 𝒅𝒙
𝟎
𝟎. 𝟐
= [(𝟎 + 𝟏) + 𝟐(𝟎. 𝟎𝟎𝟖 + 𝟎. 𝟎𝟔𝟒 + 𝟎. 𝟐𝟏𝟔
𝟐
+ 𝟎. 𝟓𝟏𝟐)]

x 0 0.2 0.4 0.6 0.8 1.0


y=f(x) 𝒚𝟎 𝒚𝟏 =0.008 𝒚𝟐 =0.064 𝒚𝟑 =0.216 𝒚𝟒 =0.512 𝒚𝟓 =1
=𝟎
=0.26

NUMERICAL INTEGRATION: Simpson’s 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. 3a). 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.3b). The formulas
that result from taking the integrals under these polynomials are
called Simpson’s rules.
(a) Graphical depiction of Simpson’s 1/3 rule: It consists of taking
the area under a parabola connecting three points. (b) Graphical
depiction of Simpson’s 3/8 rule: It consists of taking the area under
a cubic equation connecting four points.
𝟏
For Simpson’s rule, the following formula applies;
𝟑
𝒙𝟎 +𝒏𝒉
∫ 𝒇(𝒙)𝒅𝒙
𝒙𝟎
𝒉
= [(𝒚𝟎 + 𝒚𝒏 ) + 𝟒(𝒚𝟏 + 𝒚𝟑 + ⋯ + 𝒚𝒏−𝟏 ) + 𝟐(𝒚𝟐 + 𝒚𝟒
𝟑
+ ⋯ + 𝒚𝒏−𝟐 )]

𝟏 𝒅𝒙 𝟏
Example: Evaluate ∫𝟎
𝟏+𝒙 𝟐 dx using Simpson’s
𝟑
rule taking h=0.25
𝟏
𝒅𝒙 𝒉
𝑰=∫ = [(𝒚𝟎 + 𝒚𝟒 ) + 𝟒(𝒚𝟏 + 𝒚𝟐 ) + 𝟐𝒚𝟐 ]
𝟎 𝟏 + 𝒙𝟐 𝟑
𝟏
f(x) = , h=0.25
𝟏+𝒙𝟐

x 0 0.25 0.50 0.75 1.00


y =f(x) 𝒚𝒐 =1 𝒚𝟏 =0.9412 𝒚𝟐 =0.8 𝒚𝟑 =0.64 𝒚𝟒 =0.5

𝟏 𝒅𝒙 𝟎.𝟐𝟓
𝑰 = ∫𝟎 = [(𝟏 + 𝟎. 𝟓) + 𝟒(𝟎. 𝟗𝟒𝟏𝟐 + 𝟎. 𝟔𝟒) + 𝟐 × 𝟎. 𝟖]
𝟏+𝒙𝟐 𝟑

= 0.7854

CLASSWORK
1. Given that
x 4.0 4.2 4.4 4.6 4.8 5.0 5.2
lo 1.3863 1.4351 1.4816 1.5261 1.5686 1.6094 1.6487
gx

𝟓.𝟐
Evaluate ∫𝟒 𝒍𝒐𝒈 𝒙 𝒅𝒙 by (i) Trapezoidal Rule (ii) Simpson’s
𝟏
Rule ANSWERS: (i) 1.82766 (ii)1.82785
𝟑

𝟒
2. Evaluate ∫𝟎 𝒆𝒙 𝒃𝒚 𝑺𝒊𝒎𝒑𝒔𝒐𝒏′ 𝒔𝑹𝒖𝒍𝒆 𝒈𝒊𝒗𝒆𝒏 𝒕𝒉𝒂𝒕 𝒆 =
𝟐. 𝟕𝟐, 𝒆𝟐 = 𝟕. 𝟑𝟗, 𝒆𝟑 = 𝟐𝟎. 𝟎𝟗, 𝒆𝟒 = 𝟓𝟒. 𝟔
ANSWER:53.87
3. A curve is drawn to pass through the points given by the
following table:
x 1 1.5 2 2.5 3.0 3.5 4.0
y 2 2.4 2.7 2.8 3 2.6 2.1
Estimate the area bounded by the curve, x-axis and the line x=1
and x=4.

ANSWER : Area= 7.78 square units

4. The following table gives the velocity v of a particle at time t:


t(seconds) 0 2 4 6 8 10 12
v(m/sec) 4 6 16 34 60 94 136
Find the distance moved by the particle in 12 secs.
ANSWER: S= 552 m.
𝝅⁄
5. calculate ∫𝟎 𝟐 𝒆𝒔𝒊𝒏𝒙 𝒅𝒙 correct to four decimal places by
Trapezoidal rule

Numerical solution of ordinary differential equations:


Fourth Order Runge-Kutta Method

Runge-Kutta metthods are one-step methods and are widely used.


Fourth order R-K method is most commonly used and is known
as Runge-Kutta method only. We can increase the accuracy of
Runge-Kutta method by taking higher order terms.
The fourth order R-K method is given by the formula:

Given the initial condition x=x0, y=y0, an ordinary differential


𝒅𝒚
equation = 𝒇(𝒙, 𝒚) can be evaluated. To obtain y1 i.e y0+1, we
𝒅𝒙
have

𝒌𝟏 = 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 )
𝒉 𝒌𝟏
𝒌𝟐 = 𝒉𝒇(𝒙𝟎 + , 𝒚𝟎 + )
𝟐 𝟐
𝒉 𝒌𝟐
𝒌𝟑 = 𝒉𝒇(𝒙𝟎 + , 𝒚𝟎 + )
𝟐 𝟐
𝒌𝟒 = 𝒉𝒇(𝒙𝟎 + 𝒉, 𝒚𝟎 + 𝒌𝟑 )
𝟏
𝒌 = (𝒌𝟏 + 𝟐𝒌𝟐 + 𝟐𝒌𝟑 + 𝒌𝟒 )
𝟔
𝒅𝒚
Example1. Solve the differential equation = 𝒙𝒚 𝒘𝒊𝒕𝒉 𝒚(𝟏) =
𝒅𝒙
𝟓 𝒇𝒐𝒓 𝒙 = 𝟏. 𝟏 𝒈𝒊𝒗𝒆𝒏 𝒕𝒉𝒂𝒕 𝒉 = 𝟎. 𝟏
Sol.
F(x,y)= xy
𝒙𝟎 = 𝟏, 𝒚𝟎 = 𝟓, 𝒉 = 𝟎. 𝟏
𝒌𝟏 = 𝒉 × 𝒇(𝒙𝟎 , 𝒚𝟎 ) = 𝟎. 𝟏 × 𝟓 = 𝟎. 𝟓
𝒉 𝒌𝟏
𝒌𝟐 = 𝒉 × 𝒇 (𝒙𝟎 + , 𝒚𝟎 + ) = 𝟎. 𝟏 × 𝒇(𝟏. 𝟎𝟓, 𝟐. 𝟕𝟓)
𝟐 𝟐
=0.1× 𝟏. 𝟎𝟓 × 𝟐. 𝟕𝟓 = 𝟎. 𝟐𝟖𝟖𝟕
𝒉 𝒌
𝒌𝟑 = 𝒉 × 𝒇(𝒙𝟎 + , 𝒚𝟎 + 𝟐) = 𝟎. 𝟏 × 𝒇(𝟏. 𝟎𝟓, 𝟐. 𝟔𝟒𝟒𝟑)
𝟐 𝟐
=0.1× 𝟏. 𝟎𝟓 × 𝟐. 𝟔𝟒𝟒𝟑=0.27765
𝒌𝟒 = 𝒉 × 𝒇(𝒙𝟎 + 𝒉, 𝒚𝟎 + 𝒌𝟑 ) = 𝟎. 𝟏 × 𝒇(𝟏. 𝟏, 𝟓. 𝟐𝟕𝟕𝟔𝟓)
= 𝟎. 𝟏 × 𝟏. 𝟎𝟓 × 𝟐. 𝟔𝟒𝟒𝟑 = 𝟎. 𝟐𝟕𝟕𝟔𝟓 = 𝟎. 𝟓𝟖𝟎𝟓𝟒
𝟏
𝒌 = (𝒌𝟏 + 𝟐𝒌𝟐 + 𝟐𝒌𝟑 + 𝒌𝟒 )
𝟔
𝟏
= (𝟎. 𝟓 + 𝟐 × 𝟎. 𝟐𝟖𝟖𝟕 + 𝟐 × 𝟎. 𝟐𝟕𝟕𝟔𝟓 + 𝟎. 𝟓𝟖𝟎𝟓𝟒)
𝟔
=0.3688
𝒚𝟏 = 𝒚𝟎 + 𝒌 = 𝟓 + 𝟎. 𝟑𝟔𝟖𝟖 = 𝟓. 𝟑𝟔𝟖𝟖

𝒚𝟏 (𝟏. 𝟏) = 𝟓. 𝟑𝟔𝟖𝟖

Example2. Using Runge-Kutta Method, solve = 𝒙𝒚 𝒇𝒐𝒓 𝒙 =


𝟏. 𝟒. 𝒊𝒏𝒊𝒕𝒊𝒂𝒍𝒍𝒚 𝒙 = 𝟏, 𝒚 = 𝟐. 𝑻𝒂𝒌𝒆 𝒉 = 𝟎. 𝟐

Example 3. Using R-k Method of order 4, find y(0.2) for the


𝒅𝒚 𝒚−𝒛
equation = , 𝒚(𝟎) = 𝟏, 𝒉 = 𝟎. 𝟐
𝒅𝒙 𝒚+𝒙

You might also like