0% found this document useful (0 votes)
15 views98 pages

Lecture 26 Integration

Uploaded by

Fareh Iqbal
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)
15 views98 pages

Lecture 26 Integration

Uploaded by

Fareh Iqbal
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/ 98

CSC475: Numerical Computing

Tanveer Ahmed Siddiqui

Department of Computer Science


COMSATS University, Islamabad
Lecture # 26

Numerical Integration

Department of Computer Science 2


Recap

Department of Computer Science 4


Today Covered
,

After completing this lecture, you should be able


to know
 Motivation/Why Numerical Integration
 Relative Error for Numerical Integration
 Rectangle and midpoint methods
 Newton-Cotes Closed Quadrature Formula
 Trapezoidal Rule
 Error Estimate in Trapezoidal Rule

Department of Computer Science


Department of Computer Science 6
What is Integral?
,

 Integration, in mathematics, technique of


finding a function g(x) the derivative of
which, Dg(x), is equal to a given function f(x).
 This is indicated by the integral sign “∫,” as in
∫f(x), usually called the indefinite integral of the
function.
 The symbol dx represents
an infinitesimal displacement along x; thus
∫f(x)dx is the summation of the product of f(x)
and dx.

Department of Computer Science


What is Integral?
,

 Finding an Integral is the reverse of


finding a Derivative

Department of Computer Science


What is Integral?
,

The definite integral, written


with a and b called the limits of integration,
is equal to g(b) − g(a), where Dg(x)
= f(x).

Department of Computer Science


What is Integral?
,

 A definite integral assigns numbers to


functions in a way that can describe
displacement, area, volume, and
other concepts that arise by
combining infinitesimal data.
 But it is easiest to start with finding
the area under the curve of a
function like this: b
Area   f(x)dx
a
Integral = area under the curve

Department of Computer Science


Integration or anti derivative

Indefinite Integrals Definite Integrals

Indefinite Integrals of a Definite Integrals are


function are functions numbers.
that differ from each
other by a constant.
1 2 1
x 1
x2 0 xdx  2 
2
 x dx  2  c 0

Department of Computer Science 11


Warmup

Department of Computer Science 14


The need for numerical integration

Department of Computer Science 15


Challenge yourself

Department of Computer Science 16


Motivation

 Let a train start from rest with a velocity as given


in the following table for time t
Time(t) 0 10 30 40 55 60
Velocity(V) 0 20 35 43 48 52

 Can we find the distance travelled in 60


seconds?
 Yes(How)
 Use Numerical Integration

Department of Computer Science 17


What is numerical integration?

Department of Computer Science 18


Numerical Integration

 Numerical integration is the approximate


computation of an integral using numerical
techniques.
 The numerical computation of an integral is
sometimes called quadrature.
 Ueberhuber (1997, p. 71) uses the word "quadrature"
to mean numerical computation of a
univariate integral, and "cubature" to mean numerical
computation of a multiple integral.

Department of Computer Science 19


Approaches to Numerical Integration

Department of Computer Science 20


Approaches to numerical Integration

 In numerical integration, the range of integration


(b – a) is divided into a finite number of
intervals.
 Various methods have been developed for
carrying out numerical integration.
 In each of these methods, a formula is derived
for calculating an approximate value of the
integral from discrete values of the integrand.

Department of Computer Science 21


Approaches to numerical Integration

 The methods can be divided into groups:


 Open methods and closed methods.
 Newton-Cotes integration formulas
 Gaussian Quadrature formulas

Department of Computer Science 22


Closed methods

 In closed integration methods, the endpoints of


the interval (and the integrand) are used in the
formula that estimates the value of the integral.

 The trapezoidal and Simpson's methods are


closed methods

Department of Computer Science 23


Open methods

 In open integration methods, the interval of


integration extends beyond the range of the
endpoints that are actually used for calculating
the value of the integral.

 The midpoint method and Gauss quadrature are


open methods.

Department of Computer Science 24


Open and Closed methods

 Difference between closed and open methods

Department of Computer Science 25


Newton-Cotes Methods

 In Newton-Cote Methods, the function is


approximated by a polynomial of order n.
 Computing the integral of a polynomial is easy.

a
b
f ( x)dx  
a
b
a
0  a1 x  ...  a n x 
n
dx
b (b 2  a 2 ) (b n 1  a n 1 )
a
f ( x)dx a0 (b  a)  a1
2
 ...  an
n 1

Department of Computer Science 26


Newton-Cotes Methods

 When the original integrand is an analytical


function, the Newton-Cotes formula replaces it
with a simpler function.
 When the original integrand is in the form of
data points, the Newton-Cotes formula
interpolates the integrand between the given
points.
 Most commonly, as with the trapezoidal method
and Simpson's methods, the Newton-Cotes
integration formulas are polynomials of different
degrees.
Department of Computer Science 27
Other Methods

Department of Computer Science 28


Other Methods

 Then, the integral is evaluated by


direct analytical methods from calculus.
 This procedure requires numerical methods for
finding F(x) (Chapters 6 and 8), but may not
require a numerical method to evaluate the
integral if F(x) is an integrable function.

Department of Computer Science 29


Relative Error

Department of Computer Science 30


Relative Error

Department of Computer Science 31


How we Compute definite Integration

 A simple intuitive approach is to plot the function


on a grid (Fig. PT6.5) and count the number of
boxes that approximate

Department of Computer Science 32


How we Compute definite Integration

 A simple intuitive approach is to plot the function on a


grid (Fig. PT6.5) and count the number of boxes that
approximate the area.
 This number multiplied by the area of each box provides
a rough estimate of the total area under the curve.
 This estimate can be refined, at the expense of
additional effort, by using a finer grid.

Department of Computer Science 33


Why Numerical methods for Integration

 Another commonsense approach is to divide the


area into vertical segments, or strips, with a
height equal to the function value at the
midpoint of each strip (Fig. PT6.6). The area of
the rectangles can then be calculated and
summed to estimate the total area.

Department of Computer Science 34


Why Numerical methods for Integration

 In this approach, it is assumed that the value at


the midpoint provides a valid approximation of
the average height of the function for each strip.
 As with the grid method, refined estimates are
possible by using more (and thinner) strips to
approximate the integral.

Department of Computer Science 35


Numerical Integration formulas

Department of Computer Science 36


Numerical Integration formulas

Department of Computer Science 37


Numerical Integration formulas

Department of Computer Science 38


Numerical Integration formulas

Department of Computer Science 39


Numerical Integration formulas

 three straight-line segments are used to approximate the


integral. Higher-order polynomials can be utilized for the
same purpose.

Department of Computer Science 40


TRAPEZOIDAL RULE

 TRAPEZOIDAL RULE
 When n=1

Department of Computer Science 41


TRAPEZOIDAL RULE

 When n=2

Department of Computer Science 42


TRAPEZOIDAL RULE

 When n=4

Department of Computer Science 43


TRAPEZOIDAL RULE

 generalization

Department of Computer Science 44


Numerical Integration formulas

 TRAPEZOIDAL RULE

Department of Computer Science 45


Example

 Solution

Department of Computer Science 46


Your Turn

 TRAPEZOIDAL RULE

Department of Computer Science 47


Your Turn

 TRAPEZOIDAL RULE

Department of Computer Science 48


SIMPSON’S 1/3 RULE
 SIMPSON’S RULE
 It is most commonly formula for the
approximation integration.
 Similar to trapezoidal rule (trapezoidal method relies on
approximating the integrand by a straight line.)

 Divide required area into n number of strips with


equal width (even n)
 Gives better approximation then trapezoidal rule
 SIMPSON’S 1/3 RULE (uses quadratic polynomial to
approximate integrand)

 SIMPSON’S 3/8 RULE (uses cubic polynomial to


approximate integrand)
Department of Computer Science 49
SIMPSON’S 1/3 RULE

 A better approximation can possibly be obtained


by approximating the integrand with a nonlinear
function that can be easily integrated
 The coefficients of a quadratic polynomial can be
determined from three points

Department of Computer Science 50


Numerical Integration formulas

 SIMPSON’S 1/3 RULE

 if two conditions are satisfied:


 • The subintervals must be equally spaced.
 • The number of subintervals within [a, b] must be an
even number.

Department of Computer Science 51


Example

 SOLUTION

Department of Computer Science 52


Your Turn

 SIMPSON’S 1/3 RULE

Department of Computer Science 53


Your Turn

 SIMPSON’S 1/3 RULE

Department of Computer Science 54


Numerical Integration formulas

 SIMPSON’S 3/8 RULE


3

Department of Computer Science 55


Example

 SOLUTION

Department of Computer Science 56


Your Turn

 SIMPSON’S 3/8 RULE


3

Department of Computer Science 57


Your Turn


 SIMPSON’S 3/8 RULE
3

Department of Computer Science 58


Numerical Integration formulas

 BOOLE’S RULE

Department of Computer Science 59


Example

 SOLUTION

Department of Computer Science 60


Your Turn

 BOOLE’S RULE

Department of Computer Science 61


Numerical Integration formulas

 WEDDLE’S RULE

Department of Computer Science 62


Example

 SOLUTION

Department of Computer Science 63


Your Turn

 WEDDLE’S RULE

Department of Computer Science 64


Recap: Integration methods so far
,

 Approximate f(x) with a polynomial that


could be easily integrated.
 One point: rectangular and midpoint methods
 Two points: Trapezoidal method
 More points: Simpson’s method

 Use equally spaced points

Department of Computer Science


Error Bound
,

 It is often helpful to be able to determine an


upper bound for the error in an approximation
of an integral.
 Error bound for Midpoint and Trapezoidal Rule

 We can use these bounds to determine the


value of n necessary to guarantee that the error
in an estimate is less than a specified value.
Department of Computer Science
Example
,

Department of Computer Science


Example
,

Department of Computer Science


Example
,

Department of Computer Science


Up-Shot
,

Department of Computer Science


Order of accuracy of Trapezoidal and Simpsons Rule
,

 The trapezoidal rule of integration of a


definite integral is of O(h2), while that of
Simpson’s 1/3 and 3/8 rules are of fourth-
order accurate.

Department of Computer Science


Warm-up
,

 Find the value of for the following


tabular values by taking h = 0.1 ,0.2, 0.4,
0.8 using Trapezoidal Rule

Department of Computer Science


How to improve accuracy using Trapezoidal Rule
,

 How can we get a better estimate of


integral?
 We can get a better estimate by combining
two Trapezoid estimates with intervals h and
h/2
 How we combine these two estimates?
 By successive application of Richardson’s
extrapolation
 To obtain a more accurate estimate of the value of an
integral from two less accurate estimates
 For example, two estimates with an error O(h2) can be used
for calculating an estimate with an error O(h4)
Department of Computer Science
Romberg's Integration

Successive application of
Richardson's Extrapolation

Department of Computer Science 74


Romberg Integration
,

Department of Computer Science


Romberg Integration Algorithm
,

Department of Computer Science


When do we stop?

STOP if
I (n, n)  I (n, n  1)  
or
After a given number of steps,
for example, STOP at I(4,4)

Department of Computer Science 77


Romberg Integration
,

The computations are continued until the successive values are close to each
other.
The general extrapolation formula used in this scheme is

Department of Computer Science


Up-Shot: Romberg Method

Estimates using Trapezoid method intervals of size h, h/2, h/4, h/8 ...


b
are combined to improve the approximation of f(x) dx
a

First column is obtained R(0,0)


using Trapezoid Method R(1,0) R(1,1)

R(2,0) R(2,1) R(2,2)

R(3,0) R(3,1) R(3,2) R(3,3)


The other elements
are obtained using
the Romberg Method
Department of Computer Science 79
Example

Department of Computer Science 80


Example

Department of Computer Science 81


Example

Department of Computer Science 82


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature

Department of Computer Science 84


Gauss Quadrature: Motivation

Trapezoid M ethod :
 n 1 

 
b
 
f ( xi )   f ( x0 )  f ( xn ) 
1
f ( x )dx  h 
2
a  i 1 
It can be expressed as :


n


b
f ( x )dx  ci f ( xi )
a
i 0
 h i  1,2,..., n  1
where ci  
 0.5 h i  0 and n
Department of Computer Science 85
General Integration Formula


n


b
f ( x )dx  ci f ( xi )
a
i 0
ci : Weights xi : Nodes
Problem :
How do we select ci and xi so that the formula
gives a good approximation of the integral?

Department of Computer Science 86


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature
,

Department of Computer Science


Gauss Quadrature
,

Department of Computer Science


Double Integration

Department of Computer Science 93


Double Integration
,

 An integral of the

d b

  g(x, y) dx dy = VOLUME
c a

Department of Computer Science


Department of Computer Science 95
Double Integration
,

 How we evaluate double integral using


Trapezoidal Rule or Simpson rule?
 We employ either trapezoidal rule or
Simpson’s rule, repeatedly with respect to
one variable at a time over a rectangular
region bounded by the lines x = a, x =b, y
= c, y = d d b

y=d
  g(x, y) dx dy
c a

y=c

x=a x=b
Department of Computer Science
Double Integration
,

 An integral of the
d b

  g(x, y) dx dy = VOLUME
c a

 How we evaluate double integral using


Trapezoidal Rule or Simpson rule?
 We employ either trapezoidal rule or
Simpson’s rule, repeatedly With respect to
one variable at a time over a rectangular
region bounded by the lines x = a, x =b, y
= c, y = d
Department of Computer Science
Double Integration

Department of Computer Science 98


Example

Department of Computer Science 99


Example

Department of Computer Science 100


Example

Department of Computer Science 101

You might also like