You are on page 1of 26

NUMERICAL INTEGRATION AND

DIFFERENTIATION
CHAPTER-FIVE
Chapter objectives
• Learn about some methods for numerical
integration and differentiation.
• Recognize the differing effects of data error on
the processes of numerical integration and
differentiation.
INTEGRATION AND DIFFERENTIATION
• Integration and differentiation are the key concepts presented in the
first two calculus courses and they are fundamental to solving many
engineering and science problems. While many of these problems
can be solved analytically, there are also many problems that require
numerical integration or numerical differentiation techniques.
NUMERICAL INTEGRATION
• The integral of a function for can be interpreted as the area under
the curve of between , as shown in Figure 5.1. Denoting this area as
A, the integral is written as

Figure.5.1. integral of f(x) from x=a to x=b.


INTEGRATION AND DIFFERENTIATION

Definitions:-
Integrand:-
Lower limit of integration is
Upper limit of integration is
Variable of integration is
o Numerical integration, called quadrature, involves methods for
estimating the value of a definite integral. In these methods, the
function ) is estimated or approximated by another function, chosen
so that the area under is easy to compute.
o The better the estimate of by the better the estimate of the integral
of
INTEGRATION AND DIFFERENTIATION
 Two of the most common numerical integration techniques estimate with a set
of piecewise linear functions or with a set of piecewise parabolic functions.
 If the function is estimated with piecewise linear functions, the area of the
trapezoids that compose the area under the piecewise linear functions is the
approximation to the desired integral, and the method is known as the
trapezoidal rule.
 If the function is estimated with piecewise quadratic functions, the technique is
called Simpson’s rule.
Trapezoidal Rule
In the trapezoidal rule for integration, the interval [a, b] is divided into n equal
subintervals and the curve is approximated byon each subinterval as a straight line
connecting the values Of at the ends of each subinterval. The integral A is the sum
of the approximate integrals on each subinterval. The width of each subinterval is

𝑏 −𝑎
The range of values of on the interval
∆ 𝑥=is
𝑛
INTEGRATION AND DIFFERENTIATION
The approximation of on sub interval is shown in Figure 5.2. The approximating
curve is represented by the dashed line. The approximate area of over this
subinterval is that of the trapezoid under

Figure.5.2 . Approximation of ) from (on one segment)

The full integral is then approximated by adding the integral over every subinterval.
(Multiple application of the trapezoidal rule)

or
Recall from geometry that the formula for computing the area of a trapezoid is the height times
the average of the bases (Fig. 21.5a). In our case, the concept is the same but the trapezoid is
on its side (Fig. 21.5b). Therefore, the integral estimate can be represented as

or
where, for the trapezoidal rule, the average height is the average of the function
values at the end points, or
INTEGRATION AND DIFFERENTIATION
Example:-5.1.Using the trapezoidal rule with n=4 , estimate the value of the following
definite integral. And Compare with the exact value and compute the percent error.

The exact value of this integral is

For the trapezoidal rule approximation we have


Plot of the graph
y=x 2
4 f(x4)

f(x3)
3.0625

f(x2)
2.25
f(x)

f(x1)
1.5625

f(xo)
1

0
0 0.25 0.5 0.75 1 1.25 1.5 1.75 2
x
Numerical integration
Then by substituting the values in the trapezoidal rule formula

we find that the percent error is

The MATLAB function trapz(x,y,n) where y is the integral with respect to x,


approximates the integral of a function using the trapezoidal rule, and n(optional)
performs integration along dimension n .
Use hand calculation with n=5,and the MATLAB function trapz(x,y)to approximate
the value of the following integrals. and compare with the exact value.
• The definite integral is

Then

then
Then using Trapizoidal rule

And the exact solution is found from the definite integral ln(2)=0.6931
The mat lab Trapz (xi,yi) gives 0.6956, the error decreases with increasing n.
Simpson’s Rule
• Simpson’s Rule approximates the function to be integrated with piecewise
quadratic functions,
• Let the curve of Figure 5.3 be represented by the parabola

Figure 5.3. Simpson’s rule of integration


Simpson’s Rule
The area under this curve for the interval is

The curve passes through the three points and . Then, by (parabola equation) we
have:

We can now evaluate the coefficients α, β and 


Simpson’s Rule
By substitution of (b) into (a) and (c) and rearranging we get

And adding these gives.

By substituting this in to the equation gives


Simpson’s Rule
Now, we can apply the above equation to successive segments of
any curve in the interval as shown on the curve of Figure 5.5.

Figure 5.5. Simpson’s rule of integration by successive


segments
From the Figure, we see that each segment of width h of the curve can be approximated by
a parabola through its ends and its midpoint. Thus, the area under segment is
Simpson’s Rule
.

Since each segment has width , to apply Simpson’s rule of numerical integration, the
number of subdivisions must be even. This restriction does not apply to the trapezoidal
rule of numerical integration. The value of h for simpson’s Rule of integration is found
from.
Cont.…
• Using Simpson’s rule with 4 subdivisions n=4 , compute the
approximate value of

• The exact solution is


• Solution
a=1 and b=2 and n=4
h=x=(2-1)/4=0.25.

Substituting this to the simpson’s rule of integration gives


Cont.…
By comparison of the numerical with the exact value, we
observe that the error is very small when Simpson’s method
is applied.
In Matlab we can us the function to perform the Simpson’s
method of integration.
syntax, and integrate to a relative error tol which we must
specify. If tol is omitted, it is understood to be the standard
tolerance of 0.001 .The string ‘f’ is the name of a user
defined function, and a and b are the lower and upper limits
of integration respectively.
An even number of segments must be utilized to implement the method. In addition, the
coefficients “4” and “2” in Eq. (21.18) might seem peculiar at first glance. However, they
follow naturally from Simpson’s 1/3 rule, The odd points represent the middle term for each
application and hence carry the weight of 4 from Eq. (21.15). The even points are common to
adjacent applications and hence are counted twice.
Exercise
1. Use the trapezoidal approximation to compute the values of the following
definite integrals on the left (a to d) and use sympson’s approximation for those on
the right and compare your results with the analytical values. Verify your answers
with the MATLAB and functions.
21-11:-Evaluate the integral of the following tabular data with
(a)the trapezoidal rule and (b)Simpson’s rules:

You might also like