0% found this document useful (0 votes)
24 views14 pages

CH-8-Numerical Integration Spring 24-25

This document discusses numerical integration methods essential for approximating definite integrals that cannot be solved analytically, highlighting techniques such as Gaussian quadrature and Newton-Cotes methods. It explains the derivation of various quadrature rules, including the Trapezoidal rule and Simpson's rule, along with their precision and error estimates. Additionally, it covers composite quadrature rules for improved accuracy by dividing intervals into subintervals for integration.
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)
24 views14 pages

CH-8-Numerical Integration Spring 24-25

This document discusses numerical integration methods essential for approximating definite integrals that cannot be solved analytically, highlighting techniques such as Gaussian quadrature and Newton-Cotes methods. It explains the derivation of various quadrature rules, including the Trapezoidal rule and Simpson's rule, along with their precision and error estimates. Additionally, it covers composite quadrature rules for improved accuracy by dividing intervals into subintervals for integration.
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/ 14

Spring 2024-2025

Mathematical Methods of Engineering


Lecture Note 8
Numerical Integration

8.1 Introduction
Numerical integration is an essential tool used by scientists and engineers to obtain
approximate values for definite integrals that cannot be solved analytically. For example,
the integral
0.5 − x 2
0
e dx

has no closed form solution. The function exp( − x 2 ) is a continuous bounded function over
the interval [0, 0.5] and hence the integral exists. But it is not possible to evaluate it
analytically. Numerical technique is also required when the data for variables are available
in the form of table, but no mathematical relationship between them is known, as is often
the case of experimental data.
The purpose of this chapter is to develop the basic methods of numerical integration.

8.2 Method of Numerical Integration


Recall the definition of definite integral-
n
 f (cr )xr
b
 a f ( x)dx = lim
n → r =1
( xr ) max → 0
where x r = x r − x r −1 and x r −1  c r  x r , r = 1, 2, 3,  , n .
For numerical integration we shall take the formula as
b n
 a f ( x)dx =  r f ( xr ) + E
r =1
where x r are called the nodes which are distributed within the limits of integration [a, b],
 r are called the weighting factors and E is the error.

8.3 Gaussian Quadrature Rule


In Gaussian quadrature formulas, the nodes and weights are determined by using a
polynomial of as high degree as possible for f (x). If there are n nodes and n weighting
factors, we need to find 2n equations to determine 2n unknowns. This may be achieved by
taking the formula exact i.e. ( P2n ) = 0 for a polynomial of degree 2n. Using the fact that
integration is additive, it will suffice to require that the integration formula is exact for 2n
functions f ( x) = 1, x, x 2 ,, x 2n .

Degree of Precision: A quadrature formula is said to be of precision m, if it produces exact


results ( E ( Pm ) = 0) when f(x) is a polynomial  m but E ( Pm+1 )  0 .
Example 8.1: Derive the quadrature rule of the form
ℎ ℎ
∫0 𝑓(𝑥)𝑑𝑥 ≈ 𝑎𝑓 (3 ) + 𝑏𝑓(ℎ) and using this quadrature rule find the following integral to 3
d.p :
𝟎.𝟖
∫ 𝐜𝐨𝐬 (√𝟏 + 𝒙𝟐 ) 𝒅𝒙
𝟎.𝟐

1
Spring 2024-2025

Solution: Here there are two unknowns 𝑎 and 𝑏. So, we will use 𝑓(𝑥) = 1 and then 𝑓(𝑥) = 𝑥.[If
there are three unknowns, we will use 𝒇(𝒙) = 𝟏, 𝒇(𝒙) = 𝒙 & 𝒇(𝒙) = 𝒙𝟐 ].


Now for 𝑓(𝑥) = 1 we can write 𝑓 (3 ) = 1 & 𝑓(ℎ) = 1.
ℎ ℎ
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 1 𝑑𝑥 = 𝑎 + 𝑏
0 0
 ℎ = 𝑎 + 𝑏……………………… (1)
ℎ ℎ
Now for 𝑓(𝑥) = 𝑥 we can write 𝑓 (3 ) = 3 & 𝑓(ℎ) = ℎ.
ℎ ℎ

∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑥 𝑑𝑥 = 𝑎 𝑓 ( ) + 𝑏𝑓(ℎ)
0 0 3
ℎ2 ℎ
2
= 𝑎 3 + 𝑏ℎ
3ℎ
 𝑎 + 3𝑏 = 2 ……………………. (2)
3ℎ ℎ
Solving (1) and (2) we get 𝑎 = 4 & 𝑏=4
ℎ 3ℎ ℎ ℎ
Thus, we get ∫0 𝑓(𝑥)𝑑𝑥 = 4 𝑓 (3 ) + 4 𝑓(ℎ)
Here we have limit 0 & h but if the limits are 𝑥0 & 𝑥𝑖 other than 0 & ℎ then the formula changes as
below
𝑥1
3ℎ ℎ ℎ
∫ 𝑓(𝑥)𝑑𝑥 = 𝑓 (𝑥0 + ) + 𝑓(𝑥1 )
𝑥𝑜 4 3 4
Now
0.8
∫ 𝑐𝑜𝑠(√1 + 𝑥 2 )𝑑𝑥
0.2

Here 𝑓(𝑥) = 𝑐𝑜𝑠√1 + 𝑥 2 ; 𝑥0 = 0.2, 𝑥1 = 0.8 , ℎ = 0.6


0.8
3 ∗ 0.6 0.6
∫ 𝑐𝑜𝑠(√1 + 𝑥 2 )𝑑𝑥 = 𝑓(0.2 + 0.2) + 𝑓(0.8)
0.2 4 4

3∗0.6 0.6
= 4 𝑓(0.4) + 4
𝑓(0.8)
= 0.25619187

8.4 Newton-Cotes Quadrature Rule

If the nodes x r ’s are uniformly distributed in [𝑎, 𝑏] with x0 = a , x n = b and the spacing
(𝑏−𝑎)
ℎ = 𝑛 , the method is known as Newton-Cotes integration method and has the order 𝑛.
When both the end points of the interval are included as nodes, the methods are called closed
type methods, otherwise they are called open type methods.

Closed Newton Cotes Quadrature Rule

Assume that x r = x0 + rh are equally spaced nodes and f r = f ( x r ). the first few Newton-
Cotes quadrature formulas are listed below:

8.4.1 Trapezoidal Rule

For 𝑛 = 1, we obtain the Trapezoidal rule.


In this case, the quadrature rule is of the form-
2
Spring 2024-2025

x1
 x0 f ( x)dx  af ( x0 ) + bf ( x1)
where, h = x1 − x0 .
To make the simplification short and simple, the axis is translated to make x 0 as the origin.
Thus, the formula we are looking for is of the form
h
 0 f ( x)dx  af (0) + bf (h)
For two unknown parameters we may assume that the method is exact for 𝑓(𝑥) = 1 and 𝑥.
Thus
h
= x = h = a + b
h
f ( x) = 1 ,  0
dx (1)
0
h
h  x2  h2
f ( x) = x ,  0
x dx =  = = bh
 2  0 2
h
or b= (2)
2
From (1), we have
h h
a = h−b = h− =
2 2
The Trapezoidal rule becomes
h h
 0 f ( x)dx  2 [ f (0) + f (h)]
To find the precision and an estimate of error, let us take the rule is of the form
h h
 0 f ( x)dx = 2 [ f (0) + f (h)] + E
Taking f ( x) = kx 2 , we have+
h h kh3 kh3 1
E =  0 kx2dx − kh2 = − = − kh3
2 3 2 6
Here E  0 . Hence the degree of precision is 2 − 1 = 1 .

Note that f ( x) = 2k


Assuming that 2k = f (e) for 0  e  h we can write the error term as
h
E = − h2 f (e) .
12
The Trapezoidal rule for arbitrary points x0 , x1 with step size h can be obtained by
identifying the points 0 by x 0 , h by x1 = x0 + h . In this case f (0) = f ( x0 ) and f (h) = f ( x1 ) .
Thus

 x0 f ( x)dx  2  f ( x0 ) + f ( x1)
x1 h

  f 0 + f1 
h
2
where the notation f ( x r ) = f r is used.

3
Spring 2024-2025

8.4.2 Simpson’s Rule (Simpson 1/3 Rule)


For n = 2, we obtain the Simpson’s rule (Simpson’s 1/3 rule)

 x0 f ( x)dx  3 ( f0 + 4 f1 + f 2 )
x2 h

where h = ( x 2 − x0 ) / 2 .
Simpson’s rule can easily be proved by considering the integral
2h
 0 f ( x)dx  af (0) + bf (h) + cf (2h)
h
or  − h f ( x)dx  af (−h) + bf (0) + cf (h)
and then by translating the axis. This is left as an exercise for the reader.

The Simpson’s rule has degree of precision three.


The error in the formula is
(x − x )
E = − 2 0 h 4 f ( 4 ) ( e) , x0  e  x2
90

8.4.3 Simpson’s 3/8-Rule

For n = 3, we obtain the Simpson’s 3/8-rule

 x0 f ( x)dx  8 ( f0 + 3 f1 + 3 f 2 + f3 )
x3 3h

where h = ( x3 − x0 ) / 3 .
The precision of the rule is 3.

The error in the formula is


( x3 − x0 ) 4 ( 4)
E=− h f ( e) , x0  e  x3
80
Higher order formula can be derived in a similar way.

1.0
Example 8.2: Evaluate ∫0.4 𝑓(𝑥)𝑑𝑥 numerically using the values given below.
x 0.4 0.5 0.7 1.0
f(x) 1.083 1.133 1.287 1.649

Solution: Here subinterval sizes are unequal. Using the Trapezoidal rule in each subinterval
separately, we have
1.0
0.5 − 0.4 0.7 − 0.5
∫ 𝑓(𝑥)𝑑𝑥 = (1.133 + 1.083) + (1.287 + 1.133)
0.4 2 2
1.0 − 0.7
+ (1.649 + 1.287)
2
0.1 0.2 0.3
= (2.216) + (2.420) + (2.936) = 0.7932
2 2 2

4
Spring 2024-2025

Example 8.3: The table below shows the values of f (x) at different values of x:

x 0.4 0.5 0.6 0.8 1.0


f(x) 1.083 1.133 1.197 1.377 1.649
1.0
Evaluate ∫0.4 𝑓(𝑥) 𝑑𝑥 using Simpson’s rule.
Solution: Simpson’s rule is applied to two consecutive subintervals of equal length. Thus
for the given data we may divide the subintervals as follows:
1.0 0.6 1.0
∫ 𝑓(𝑥)𝑑𝑥 = ∫ 𝑓(𝑥)𝑑𝑥 + ∫ 𝑓(𝑥)𝑑𝑥
0.4 0.4 0.6

0.1
[𝑓(0.4) + 4 ∗ 𝑓(0.5) + 𝑓(0.6)]
=
3
0.2
+ [𝑓(0.6) + 4 ∗ 𝑓(0.8) + 𝑓(1.0)
3
0.1 0.2
= [1.083 + 4(1.133) + 1.197] + [1.197 + 4(1.377) + 1.649]
3 3
= 0.2271 + 0.5569 = 0.784
8.5 Composite Quadrature Rules
To avoid the use of higher order methods and still obtain accurate results, we use the
composite integration methods. We divide the interval [a, b] into several subintervals and
evaluate the integral in each required number of subintervals by a particular method.

Composite Trapezoidal Rule

We divide the interval [a, b] into N subintervals [ x r −1 , x r ] , each of length h = (b − a ) / N ,


x0 = a , x N = b and x r = x0 + rh, r = 1, 2, 3,  , N . We write
b x1 x2 xN
a f ( x)dx =x0 f ( x)dx + x1 f ( x)dx +    + 
xN −1
f ( x)dx

Evaluating each integral on the right-hand side by the trapezoidal rule


b h h h
a f ( x)dx  2 ( f 0 + f1 ) + 2 ( f1 + f 21 ) +    + 2 ( f N −1 + f N )
h
 [ f 0 + f N + 2( f1 + f 2 + f 3 +    + f N −1 )]
2
The error in the formula is
b−a 2
ET = − h f (e) , aeb
12

5
Spring 2024-2025

Composite Simpson’s Rule

We divide the interval [a, b] into N, an even number of subintervals [ x r , x r +1 ] , each of


length h = (b − a ) / N , x0 = a , x N = b by using x r = x0 + rh, r = 0,1, 2, 3,  , N . We write
b x2 x4 xN
a f ( x)dx = 
x0
f ( x)dx + 
x2
f ( x)dx +    + 
xN −2
f ( x)dx
Evaluating each integral on the right-hand side by the Simpson’s rule
b h h h
a f ( x)dx  3 ( f 0 + 4 f1 + f 2 ) + 3 ( f 2 + 4 f 3 + f 4 ) +    + 3 ( f N −2 + 4 f N −1 + f N )
h
 ( f 0 + 4 f1 + 2 f 2 + 4 f 3 + 2 f 4 +    + 2 f N − 2 + 4 f N −1 + f N )
2
The error in the formula is
h4
ES = − (b − a) f ( 4) (e) , aeb
180

Example 8.4: The values of f (x) are given for different values of x below.

x 0 0.2 0.4 0.6 0.8 1.0 1.2


f(x) 1.000 1.780 1.954 2.000 1.976 1.909 1.814
1.2
Evaluate I = 0 f ( x)dx using extrapolation and (i) trapezoidal rule (ii) Simpson’s rule

Solution: (i) Consider the integral with trapezoidal rule.


I T (0.2) =
0.2
1 + 2(1.780 + 1.954 + 2.000 + 1.976 + 1.909) + 1.814
2
= 0.1  22 .078 = 2.208

I T (0.4) =
0.4
1 + 2  1.954 + 2  1.976 + 1.814 = 0.2  10.674 = 2.135
2
Using Richardson extrapolation
I T (0.2) − I T (0.4) 2.208 − 2.135
I R = I T (0.2) + = 2.208 + = 2.232
2 −1
2
3

(ii) Consider the integral with Simpson’s rule


I S (0.2) =
0.2
1 + 4  1.780 + 2  1.954 + 4  2.000 + 2  1.976 + 4  1.909 + 1.814 = 2.229
3
With step size h = 0.4, the number of subintervals = 1.2 = 3 and Simpson’s rule cannot be used.
0 .4

Taking h = 0.6, we get I S (0.6) =


0.6
1 + 4  2 + 1.814 = 2.163
3
Using Richardson’s extrapolation
I S (0.2) − I S (0.6) 2.229 − 2.163
I R = I S (0.2) + = 2.229 + = 2.223
3 −1
4
80

6
Spring 2024-2025

8.6 Romberg Integration


Romberg integration is an extrapolation formula of the Trapezoidal Rule for integration. It
provides a better approximation of the integration by repeated applications of the
Richardson’s Extrapolation formula. It is known that the Trapezoidal rule approximation
 T (h) to an integral  has error behavior
 = T (h) + a2 h 2 + a4 h 4 + a6 h 6 +   
Suppose that  ( 0 ) ( n, h) is a Trapezoidal estimation of the integral  with n subintervals and
step size h. By doubling the step size, the corresponding estimate is  ( 0) (2n, h / 2) .
The first Richarson extrapolated value I (1) (2n, h / 2) is
 ( 0) (2n. h / 2) −  ( 0) (n. h)
 (2n, h / 2) =  (2n, h / 2) +
(1) (0)
has error of order (h 4 )
2 −1
2

The Simpson’s rule has an error of order (h ) . In fact, I (1) (2n, h / 2) is exactly the
4

Simpson’s rule estimate. The second improved estimate I ( 2 ) (2n, h / 2) is


 (1) (4n. h / 4) −  (1) (2n. h / 2)
 ( 2) (4n, h / 4) =  (1) (4n, h / 4) +
24 −1
has error of order (h 6 ) and so on.

1 𝑥2
Example 8.5 : Evaluate∫0 𝑥 exp ( 2 ) 𝑑𝑥 using Trapezoidal rule with 1, 2 and 4 subintervals.
Improve the results using Romberg integration.
2
Solution: Here f ( x) = x e x / 2 .
Using the trapezoidal rule we have
1
n = 1, h = (1 − 0) = 1 ;  ( 0) (1,1) = [ f (0) + f (1)] = 0.8244
2
0.5
n = 2, h = 12 = 0.5 ;  ( 0) (2, 0.5) = [ f (0) + f (1) + 2 f (0.5)] = 0.6955
2

n = 4, h = 1 = 0.25 𝐼 (0) (4,0.25) = 2 [𝑓(0) + 𝑓(1) + 2(𝑓(0.25) + 𝑓(0.5) + 𝑓(0.75))] = 0.6606


0.25
4
 ( 0) (2, 0.5) −  ( 0) (1, 1)
First order extrapolated values are  (1) (2, 0.5) =  ( 0) (2, 0.5) +
22 −1
0.6955 − 0.6244
= 0.6955 + = 0.6525
3
 ( 0) (4, 0.25) −  ( 0) (2, 0.5)
And  (1) (4, 0.25) =  ( 0) (4, 0.25) +
22 −1
0.6606 − 0.6955
= 0.6606 + = 0.6490
3
 (1) (4, 0.25) −  (1) (2, 0.5)
Second extrapolated value is  ( 2) (4, 0.25) =  (1) (4, 0.25) +
24 −1
0.6490 − 0.6525
= 0.6490 + = 0.6488
15
Results are summarized below in a Table:
n h 𝑂(ℎ2 ) 𝑂(ℎ4 ) 𝑂(ℎ6 )
1 1 0.8244
2 0.5 0.6955 0.6528
4 0.25 0.6606 0.6490 0.6488

7
Spring 2024-2025

8.7 Numerical Evaluation of Double Integrals


Multiple integrals are evaluated by expressing them as iterated integrals. For example a double
integral can be expressed as follows;
𝑏 𝑓2 (𝑥)
∬ 𝑓(𝑥, 𝑦)𝑑𝐴 = ∫ (∫ 𝑓(𝑥, 𝑦)𝑑𝑦) 𝑑𝑥
𝑅 𝑎 𝑓1 (𝑥)
or
𝑑 𝑔2 (𝑦)
∬ 𝑓(𝑥, 𝑦)𝑑𝐴 = ∫ (∫ 𝑓(𝑥, 𝑦)𝑑𝑥 ) 𝑑𝑦
𝑅 𝑐 𝑔1 (𝑦)
In computing the iterated integral of the first form, we hold x constant while integrating with
respect to y and then integrate with respect to x(vice versa for second form).
Numerical evaluation of integrals we need to choose interval length and nodal points where the
functional values to be calculated. For fixed limits, selection of interval length and nodal points
are straight forward but for variable limits interval length and nodal points should be calculated for
a fixed value of other variable. For example, in first form the interval at 𝑥 = 𝑥𝑟 is
𝑓2 (𝑥𝑟 ) − 𝑓1 (𝑥𝑟 )
𝑘𝑟 =
𝑛

Example 8.6
1.0 1.6 2𝑦 2
Using Simpson’s rule with 2-subintervals evaluate the double integral∫0.6 ∫1.0 𝑑𝑦𝑑𝑥
𝑥+𝑦

The integral is over the rectangular region bounded by0.6 ≤ 𝑥 ≤ 1.0 and 1.0 ≤ 𝑦 ≤ 1.6.
Using 2-subintervals in each direction, we have
1.0 − 0.6 1.6 − 1.0
ℎ= = 0.2 and 𝑘 = = 0.3
2 2
2𝑦 2
The integrand is𝑓(𝑥, 𝑦) = 𝑥+𝑦.

Integration using fixed values of 𝑥 = 0.6, 0.8 and 1.0 are as follows:
1.6
0.3
𝐼(0.6) = ∫ 𝑓(0.6, 𝑦)𝑑𝑦 = [𝑓(0.6,1.0) + 4𝑓(0.6,1.3) + 𝑓(0.6,1.6)]
1.0 3
0.3
= [1.25 + 4(1.779) + 2.327] = 1.0693
3

1.6
0.3
𝐼(0.8) = ∫ 𝑓(0.8, 𝑦)𝑑𝑦 = [𝑓(0.8,1.0) + 4𝑓(0.8,1.3) + 𝑓(0.8,1.6)]
1.0 3
0.3
= [1.111 + 4(1.610) + 2.133] = 0.9684
3

1.6
0.3
𝐼(1.0) = ∫ 𝑓(1.0, 𝑦)𝑑𝑦 = [𝑓(1.0,1.0) + 4𝑓(1.0,1.3) + 𝑓(1.0,1.6)]
1.0 3
0.3
= [1.0 + 4(1.47) + 1.969] = 0.8849
3

Finally combining the integral for 𝑥, we have

1.0 1.6 0.2


I(Simp) = ∫0.6 ∫1.0 𝑓(𝑥, 𝑦)𝑑𝑦𝑑𝑥 ≈ [𝐼(0.6) + 4 𝐼(0.8) + 𝐼(1.0)]
3

0.2
= [1.0693 + 4(0.9684) + 0.8849] = 0.38852
3
[MATLAB result is I = 0.38846]

8
Spring 2024-2025

Calculations are summarized in the following table:

xr yr f(x,y) I(xr, k) I(Simp)


0.6 1 1.25
0.6 1.3 1.779 1.0693
0.6 1.6 2.327
0.8 1 1.111
0.8 1.3 1.61 0.9684 0.38852
0.8 1.6 2.133
1 1 1
1 1.3 1.47 0.8849
1 1.6 1.969

Example 8.7 Using Simpson’s rule with 2-subinervals evaluate the double integral
1.4 1+𝑥 2
∫ ∫ (1 + 𝑥𝑦)𝑑𝑦𝑑𝑥
1.0 𝑥
Solution: The region of integration is1.0 ≤ 𝑥 ≤ 1.4, 𝑥 ≤ 𝑦 ≤ 1 + 𝑥 2
The integrand is 𝑓(𝑥, 𝑦) = 1 + 𝑥𝑦
1.4−1.0
With 2 equal subintervals for x, the interval length is ℎ = 2 =0.2. The end points of
subintervals are 1, 1.2 and 1.4.
The interval length for y is variable depending on the values of x.
(1 + 12 ) − 1
For 𝑥 = 1, 𝑘1 = = 0.5 and𝑦𝑟 = 1, 1.5, 2.0
2
The integral over y is
0.5
𝐼(1, 0.5) = [𝑓(1,1) + 4𝑓(1,1.5) + 𝑓(1,2.0)]
3
0.5
= [2 + 4(2.5) + 3] = 2.5
3
(1 + 1.22 ) − 1.2
For 𝑥 = 1.2 , 𝑘2 = = 0.62 and𝑦𝑟 = 1.2, 1.82, 2.44
2
0.62
The integral over y is𝐼(1.2, 0.62) = [𝑓(1.2,1.2) + 4𝑓(1.2,1.82) + 𝑓(1.2, 2.44)]
3
0.5
= [2.44 + 4(3.184) + 3.928] = 3.9482
3
(1 + 1.42 ) − 1.4
For 𝑥 = 1.4 , 𝑘3 = = 0.78 and𝑦𝑟 = 1.4, 2.18, 2.96
2
0.78
The integral over y is𝐼(1.4, 0.78) = 3 [𝑓(1.4,1.4) + 4𝑓(1.4, 2.18) + 𝑓(1.4, 2.96)]
0.78
= [2.96 + 4(4.052) + 5.144] = 6.3211
3

Finally combining the integrals for x, we have


1.4 1+𝑥 2
0.2
∫ ∫ (1 + 𝑥𝑦)𝑑𝑦𝑑𝑥 ≈ [2.5 + 4(3.9482) + 6.3211] = 1.64092
1.0 𝑥 3

[ 𝐼(exact) = 1.64061]
9
Spring 2024-2025

Summary of calculations are shown below:

kr xr yr f(xr,yr) I(xr,kr) I(Simp)


1 1 2
0.5 1 1.5 2.5 2.5
1 2 3
1.2 1.2 2.44
0.62 1.2 1.82 3.184 3.94816 1.640917
1.2 2.44 3.928
1.4 1.4 2.96
0.78 1.4 2.18 4.052 6.32112
1.4 2.96 5.144

8.8 Numerical evaluation of Integrals using MATLAB


Syntax of MATLAB commands for different types of integrals are as follows:
integral(fun, xmin, xmax)
integral2(fun, xmin, xmax, ymin, ymax)
integral3(fun, xmin, xmax, ymin, ymax,zmin,zmax)

Command for required number of digits

vpa(value, n) % to display value to n digits

Note: Define the function using “anonymous handle”. Format is shown below:
fname=@(argument) <space> formula
operation / (division) and ^ (for power) must preceded with . (dot).
sin (𝑥𝑦)
For example 𝑓(𝑥, 𝑦) = 𝑥 2 +𝑦 2
may be typed as

ff=@(x,y) sin(x*y)./(x.^2+y.^2))
This will be treated as ff(x,y).

1
Example 8.6: Evaluate ∫0 𝑒 𝑥 sin 𝑥 2 𝑑𝑥 numerically to 7 digits using MATLAB command.

>> fun=@(x) exp(x).*sin(x.^2) % enter function as @function

fun = @(x)exp(x).*sin(x.^2)

>> int=integral(fun,0,1); % command for integration


>> int7=vpa(int,7) % used to increase precision

int7 =0.662701

10
Spring 2024-2025

2 √𝑥 1
Example 8.8: Evaluate ∫0 ∫−𝑥 𝑑𝑦 𝑑𝑥 numerically using MATLAB command.
√𝑥 2 +𝑦 2
>> fun2=@(x,y) 1./sqrt(x.^2+y.^2) % define as @-function

fun2 = @(x,y)1./sqrt(x.^2+y.^2)

>> ymin=@(x) –x % lower limit as function of x

ymin = @(x)-x

>> ymax=@(x) sqrt(x) % upper limit as a function of x

ymax = @(x)sqrt(x)

>> int2=integral2(fun2, 0, 2, ymin,ymax);

>> int22=vpa(int2,7) % output to 7 digits

int22 =3.811758

𝑑𝑉
Example 8.9: Evaluate ∭𝑅 , where R is the region bounded by the coordinate
(1+𝑥+𝑦+𝑧)2
planes and the plane 𝑥 + 𝑦 + 𝑧 = 1, numerically using MATLAB command.

The integral can be written as an iterated integral of the form


1 1−𝑥 1−𝑥−𝑦
1
∫ ∫ ∫ 𝑑𝑧𝑑𝑦𝑑𝑥
0 0 0 (1 + 𝑥 + 𝑦 + 𝑧)2

MATLAB commands and output

>> clear
>> fun3=@(x,y,z) 1./(x+y+z+1).^2 % define the integrand as a @-function

fun3 = @(x,y,z)1./(x+y+z+1).^2

>> ymax=@(x) 1-x

ymax = @(x)1-x

>>zmax=@(x,y) 1-x-y

zmax = @(x,y)1-x-y

>> int3=integral3(fun3,0,1,0,ymax,0,zmax); % command for integration

>> int31=vpa(int3,7) % result using 7 digits.

int31 =0.05685282

11
Spring 2024-2025

Exercise 8

1. The table shows the power P supplied to the driving wheels of a car as a function of
the speed 𝑣. If the mass of the car is m=2000 kg, determine the time ∆𝑡 it takes for
the car to accelerate from 1𝑚/𝑠 to 6 𝑚/𝑠. Use the trapezoidal rule for integration.
Hint:
6𝑠

∆𝑡 = 𝑚 ∫ (𝑣/𝑝)𝑑𝑣
1𝑠
which can be derived from Newton’s law 𝐹 = 𝑚(𝑑𝑣/𝑑𝑡) and the definition of
power 𝑃 = 𝐹𝑣.

v(m/s) 0 1.0 1.8 2.4 3.5 4.4 5.1 6


P(kW) 0 4.7 12.2 19.0 31.8 40.1 43.8 43.2

2. The table below shows the values of f (x) at different values of x:

x 1.2 1.4 1.6 1.8 2.0


f(x) 3.728 4.124 4.525 5.123 5.626
2.0
(i) Use Trapezoidal rule and Richardson’s extrapolation to estimate 1.2 f ( x) dx .
2.0
(ii) Use Simpson’s rule and Richardson’s extrapolation to estimate 1.2 f ( x) dx .

3. The table below shows the values of f (x) at different values of x:


x 1.2 1.35 1.5 1.65 1.8
f(x) 3.32 3.86 4.48 5.21 6.05
1.8
(i) Use Trapezoidal rule and Richardson’s extrapolation to estimate 1.2 f ( x) dx .
1.8
(ii) Use Simpson’s rule and Richardson’s extrapolation to estimate 1.2 f ( x) dx .

4. A river is 50 meters wide. The depth ‘d’ in meters at distance x meters from one back
is given by the following table. Calculate the arc of cross-section of the river using
Trapezoidal rule.
x 0 10 20 30 40 50
d 0 4 7 9 12 15

5. The car gives the velocity 𝑣 of a moving particle at time t seconds. Find the
distance covered by the particle in 8 seconds.
t 0 2 4 6 8 9
v 4 6 16 34 60 75

12
Spring 2024-2025

6. Derive the following quadrature rules :


2ℎ
(a) ∫0 𝑓(𝑥)𝑑𝑥 ≈ 𝑎𝑓(0) + 𝑏𝑓(ℎ) + 𝑐𝑓(2ℎ)
ℎ ℎ
(b) ∫0 𝑓(𝑥)𝑑𝑥 ≈ 𝑎𝑓 (3) + 𝑏𝑓(ℎ)
In each case find its degree of precision.
Use the above quadrature rule to estimate the following integrals to 3 decimal places.
0.8 1.6 2
(i) ∫0.2 cos (√1 + 𝑥 2 ) 𝑑𝑥, (ii) ∫1 𝑥 2 𝑒 1−𝑥 𝑑𝑥.
7. The table below shows the values of f (x) at different values of x:

x 1.0 1.2 1.4 1.6 1.8


f(x) 1.831 2.592 3.515 4.643 5.926

1.8
Evaluate ∫1.0 𝑓(𝑥) 𝑑𝑥 using Tapezoidal rule with 1, 2 and 4 subintervals.
Improve your results using Romberg integration.

8. Compute following integrals using Trapezoidal rule with subintervals 1, 2 and 4.


Improve your results using Romberg integration. And write MATLAB code to evaluate
the integrals. Also find exact result ( if possible ) & find percentage error.

1 1.8 𝑥2 1 ln (1+𝑥) 𝜋 sin2 𝑥


(a) ∫0 √1 + 2𝑥 3 𝑑𝑥 (b) ∫1 exp ( 2 ) 𝑑𝑥 (c) ∫0 𝑑𝑥 (d) ∫0 𝑑𝑥
1+𝑥 2 5+4 cos 𝑥

9. Using Simpson’s rule with two subintervals evaluate the following double integrals
and also write MATLAB code to evaluate.
1.5 1 2.0 1.5
(a) ∫1 ∫0 (𝑥 2 + 2√𝑦)𝑑𝑦𝑑𝑥 , (b) ∫1.4 ∫1.0 ln(2𝑥 + 𝑦) 𝑑𝑥𝑑𝑦 ,
2 1 0.8 2
(c) ∫1 ∫0 (1 + 8𝑥 )𝑑𝑦𝑑𝑥 , (d) ∫0.2 ∫0 √𝑥 + 𝑦 𝑑𝑦𝑑𝑥 .
0.5 1 sin(𝑥𝑦) 2 2
(e) ∫0 ∫0 𝑑𝑦𝑑𝑥 (f) ∫1 ∫1 2exp(𝑦⁄𝑥) 𝑑𝑦𝑑𝑥
1+𝑥𝑦

10. Evaluate the following integrals using MATLAB commands.


2 6 1
(a) ∫0 ∫3 ∫−1(𝑒 2𝑥 sin 𝑦 + 𝑧 ln 𝑦) 𝑑𝑥𝑑𝑦𝑑𝑧
2 3 1
(b) ∫0 ∫0 ∫0 𝑥𝑦𝑧 𝑑𝑧𝑑𝑦𝑑𝑥
1.8
11. The function 𝑓(𝑥) is given in the following tabulated form. Compute ∫0 𝑓(𝑥)𝑑𝑥 with
ℎ = 0.3 and ℎ = 0.6
(a) Use the composite Trapezoidal method
(b) Improve your result using Romberg integration method
x 0 0.3 0.6 0.9 1.2 1.5 1.8
f(x) 0.5 0.6 0.8 1.3 2 3.2 4.8

13
Spring 2024-2025

[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish Subramaniam,
Problem # 9.1, Page # 374]

12. To estimate the surface area and volume of a wine barrel, the
diameter of the barrel is measured at different points along the
barrel. The surface area, 𝑆, and volume, 𝑉, can be determined
by:
𝐿 𝐿
𝑆 = 2𝜋 ∫0 𝑟 𝑑𝑧 and 𝑉 = 𝜋 ∫0 𝑟 2 𝑑𝑧
Use the data given in the table to determine the volume and
surface area of the barrel
𝑧 (in.) -18 -12 -6 0 6 12 18
𝑑 (in.) 0 2.6 3.2 4.8 5.6 6 6.2
(a) Use the composite trapezoidal method.
(b) Use the composite Simpson’s 1/3 method.
(c) Use the Romberg integration method.
[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish Subramaniam,
Problem # 9.2, Page # 374]

13. To estimate the surface area and volume of a wine bottle, the radius of
the bottle is measured at different heights. The surface area, 𝑆, and volume,
𝑉, can be determined by:
𝐿 𝐿
𝑆 = 2𝜋 ∫0 𝑟 𝑑𝑧 and 𝑉 = 𝜋 ∫0 𝑟 2 𝑑𝑧
Use the data given below to determine the volume and surface area of the
vase:
𝑧 (cm) 0 2 4 6 8 10 12
𝑟 (cm) 10 11 11.9 12.4 13 13.5 13.8
(a) Use the composite trapezoidal method
(b) Use the Romberg integration method.
[Ref. Numerical Methods for engineers and Scientists – Amos Gilat, Vish Subramaniam,
Problem # 9.3, Page # 374]

14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy