0% found this document useful (0 votes)
41 views145 pages

Metnum 2 Integration RM

The document discusses numerical integration techniques. It introduces the concept of quadrature, which refers to approximating the definite integral of a function through numerical methods. Several techniques are covered, including the trapezoid rule, Simpson's rule, Gaussian quadrature, and adaptive Simpson's scheme. The document motivates the need for numerical integration when integrals cannot be evaluated analytically or when the integrand is defined by a discrete data set rather than a mathematical equation. It also discusses how integrals can be approximated as Riemann sums by partitioning the domain into subintervals and using upper and lower bounds based on the maximum and minimum function values within each interval.

Uploaded by

amanda.120350091
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)
41 views145 pages

Metnum 2 Integration RM

The document discusses numerical integration techniques. It introduces the concept of quadrature, which refers to approximating the definite integral of a function through numerical methods. Several techniques are covered, including the trapezoid rule, Simpson's rule, Gaussian quadrature, and adaptive Simpson's scheme. The document motivates the need for numerical integration when integrals cannot be evaluated analytically or when the integrand is defined by a discrete data set rather than a mathematical equation. It also discusses how integrals can be approximated as Riemann sums by partitioning the domain into subintervals and using upper and lower bounds based on the maximum and minimum function values within each interval.

Uploaded by

amanda.120350091
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/ 145

Integration

Numerical Method
Robiatul Muztaba, S.Si., M.Si.
SAP – ITERA
Quadrature

• We talk in terms of Quadrature Rules


– 1. The process of making something square.
– 2. Mathematics The process of constructing a square equal in area to a given
surface.
– 3. Astronomy A configuration in which the position of one celestial body is
90° from another celestial body, as measured from a third.

December 6, 2023 2
Outline
• Definite Integrals
• Lower and Upper Sums
– Reimann Integration or Reimann Sums
• Uniformly-spaced samples
– Trapezoid Rules
– Romberg Integration
– Simpson’s Rules
– Adaptive Simpson’s Scheme
• Non-uniformly spaced samples
– Gaussian Quadrature Formulas
December 6, 2023 3
Motivation
What does an integral represent?
d b
 f ( x)dxdy = volume
b

a
f ( x)dx = area c a

Basic definition of an integral: f(x)


n
f ( x )dx = lim f ( xk )x
b
a n →
k =1

where x = b − a
n

sum of height  width x


December 6, 2023 4
Motivation
b
• Evaluate the integral, I =  f ( x)dx without doing the calculation
a

analytically.
• Necessary when either:
– Integrand is too complicated to integrate analytically
2 2 + cos(1 + x ) 0.5 x

0
1 + 0.5 x
e dx

– Integrand is not precisely defined by an equation, i.e., we are given a set of


data (xi, yi), i = 1, 2, 3, …,n
December 6, 2023 5
Reimann Integral Theorem
• Integration is a summing process. Thus virtually all numerical
approximations can be represented by
n
I =  f ( x )dx =  wi f ( xi ) + Et
b

a
i =1

in which wi are the weights, xi are the sampling points, and Et is the
truncation error
• Valid for any function that is continuous on the closed and bounded
interval of integration.
December 6, 2023 6
Partitioning the Integral
• The most common numerical integration formula is based on equally
spaced data points.
xn
 x0
f ( x)dx

• Divide [x0 , xn] into n intervals (n1)


x1 x2 xn
xn

x0
f ( x)dx =  f ( x) +  f ( x) +
x0 x1
+ 
xn−1
f ( x)

December 6, 2023 7
Upper Sums

• Assume that f(x)>0 everywhere.


• If within each interval, we could determine the maximum
value of the function, then we have:
xn n −1

 f ( x)   M ( x
i i +1 − xi )
• where x0 i =0

M i = sup  f ( x) : xi  x  xi +1 Supremum - least


upper bound

December 6, 2023 8
Upper Sums

• Graphically:

x0 x1 x2 x3 x4

December 6, 2023 9
Lower Sums

• Likewise, still assuming that f(x)>0 everywhere.


• If within each interval, we could determine the minimum
value of the function, then we have:

xn n −1
• where  f ( x)   m ( x
i i +1 − xi )
x0 i =0

mi = inf  f ( x) : xi  x  xi +1
Infimum - greatest
lower bound

December 6, 2023 10
Lower Sums

• Graphically

x0 x1 x2 x3 x4

December 6, 2023 11
Finer Partitions
• We now have a bound on the integral of the function for some
partition (x0,..,xn):
n −1 xn n −1

m (x
i =0
i i +1 − xi )   f ( x)   M i ( xi +1 − xi )
i =0
x0

• As n→, one would assume that the sum of the upper bounds and
the sum of the lower bounds approach each other.
• This is the case for most functions, and we call these Riemann-
integrable functions.

December 6, 2023 12
Bounding the Integral

• Graphically

x0 x1 x2 x3 x4

December 6, 2023 13
Bounding the Integral

• Halving each interval (much like Lab1):

x0 x3 x5 x7 x9

December 6, 2023 14
Bounding the Integral

• One more time:

x0 x5 x7 x9 x11

December 6, 2023 15
Monotonic Functions

• Note that if a function is monotonically increasing (or


decreasing), then the lower sum corresponds to the left
partition values, and the upper sum corresponds to the right
partition values.

x0 x3 x5 x7 x9
December 6, 2023 16
Lab1 and Integration

• Thinking back to lab1, what were the limits or the


integration?
• Is the sin function monotonic on this interval?
• Should the Reiman sum be an upper or lower sum?

December 6, 2023 17
Polynomial Approximation
• Rather than search for the maximum or minimum, we replace f(x)
with a known and simple function.
• Within each interval we approximate f(x) by an mth order
polynomial.
pm ( x) = a0 + a1 x + a2 x 2 + ... + am x m

December 6, 2023 18
Newton-Cotes Formulas
• The m’s (order of the polynomials) may be the same or different.

xn x0+m1 x0+m1+m2 xn
 x0
f ( x)dx = 
x0
pm1 ( x)dx + 
x0+ m1
pm2 ( x)dx + ... + 
xn−mn
pmn ( x)dx

• Different choices for m’s lead to different formulas:


m Polynomial Formula Error
1 linear Trapezoid O(h 2 )
2 quadratic Simpson' s 1/3 O(h 4 )
3 cubic Simpson' s 3/8 O(h 4 )
December 6, 2023 19
Trapezoid Rule
• Simplest way to approximate the area under a curve – using first
order polynomial (a straight line)
• Using Newton’s form of the interpolating polynomial:
f (b ) − f (a )
p1 (x ) = f (a ) + (x − a )
b−a

• Now, solve for the integral:

I =  f ( x )dx   p1 (x )dx
b b

a a

December 6, 2023 20
Trapezoid Rule

 f (b ) − f (a ) 
I    f (a ) + (x − a )dx
b

a
 b−a 
Trapezoid Rule
f(b)

I
(b − a)
 f (a ) + f (b)
f(a)
2

I  width  average height


a b
December 6, 2023 21
Trapezoid Rule

• Improvement?

x0 x1 x2 x3 x4

December 6, 2023 22
Trapezoid Rule Error
• The integration error is:
(b − a )
f ( )h 3 = − f ( )h 2
1
Et = −
12 12
O(h 2 )

• Where h = b - a and  is an unknown point where a <  < b


(intermediate value theorem)

• You get exact integration if the function, f, is linear (f = 0)

December 6, 2023 23
Example
− x2
Integrate from f ( x) = e a = 0 to b = 2

Use trapezoidal rule:

2
I = e − x2
dx
0


(b − a)
 f (a ) + f (b) = ( 2 − 0)
 f (2) + f (0)
2 2
= 1  (e −4 + e0 ) = 1.0183

December 6, 2023 24
Example

Estimate error: Et = − 1 f ( )h 3


12
Where h = b - a and a <  < b

Don’t know  - use average value


f ( x) = ( −2 + 4 x )e
2 − x2
f (0) = −2
h = 2−0= 2 f (2) = 0.2564

23  f (0) + f (2 )
Et  E a = − = 0.58
12 2
December 6, 2023 25
More intervals, better result [error  O(h2)]
7 7

6
n=2 6
n=3
5 5

4 4

3 3

2 2

1 1

0 0
3 5 7 9 11 13 15 3 5 7 9 11 13 15

7 7

6
n=4 6
n=8
5 5

4 4

3 3

2 2

1 1

0 0
3 5 7 9 11 13 15 3 5 7 9 11 13 15

December 6, 2023 26
Composite Trapezoid Rule
• If we do multiple intervals, we can avoid duplicate function
evaluations and operations:
• Use n+1 equally spaced points.
b−a
• Each interval has: h=
n
• Break up the limits of integration and expand.
a +h a +2h
f (x )dx +  f (x )dx + ... +  f (x )dx
b
I =
a a +h b−h

December 6, 2023 27
Composite Trapezoid Rule
• Substituting the trapezoid rule for each integral.
a+h a+2h
I =  f ( x ) dx + a+h f ( x ) dx + ... f ( x ) dx
b
+
a b−h

(a + h − a) ( a + 2h − a − h )
=  f ( a ) + f ( a + h ) +  f ( a + h ) + f ( a + 2h )
2 2
(b − b + h)
+.... +  f ( b − h ) + f ( b )
2

• Results in the Composite Trapezoid Formula:


h n −1

I =  f (a ) + 2 f (a + ih ) + f (b)
2 i =1 
December 6, 2023 28
Composite Trapezoid Rule

• Think of this as the width times the average height.

h n −1

I =  f (a ) + 2 f (a + ih ) + f (b )
2 i =1 
n −1
f (a ) + 2 f (a + ih ) + f (b )
= (b − a ) i =1
2n
width
Average height

December 6, 2023 29
Error

• The error can be estimated as:


=
(b − a )h 2
f  =
(b − a)
3
f 
2
Ea 2 O(h )
12 12n


• Where, is thef average second derivative.
• If n is doubled, h → h/2 and Ea → Ea/4
• Note, that the error is dependent upon the width of the area
being integrated.
December 6, 2023 30
Example

• Integrate: f (x ) = 0.3 + 20 x − 140x 2 + 730x 3 − 810x 4 + 200x 5

• from 40

a=0.2 35

to 30

b=0.8 25

20

15

10

0
0 0.2 0.4 0.6 0.8 1 1.2
December 6, 2023 31
Example

• A single application of the Trapezoid rule.


f (a ) + f (b )
I = (b − a )
2
34.22 + 3.81
= (0.8 − 0.2 )
2
= 11.26
• Error:
f ( )(b − a )
1
Et = −
3

12

December 6, 2023 32
Example

• We don’t know  so approximate with average f

f (x ) = 20 − 280x + 2190x 2 − 3240x 3 + 1000x 4

f (x ) = −280 + 4380x − 9720x 2 + 4000x 3


0.8

f ( x ) =

0.2
f  dx
0.8 − 0.2
f (0.8) − f (0.2)
= = −131.6
0.8 − 0.2
December 6, 2023 33
Example

• The error can thus be estimated as:


( b − a) h ( b − a)
2 3

Et = f  = 2
f 
12 12n
1
= − ( −131.6 )( 0.8 − 0.2 ) = 2.37
3

12

December 6, 2023 34
True value of integral is 12.82. Trapezoid
rule is 11.26 - within approx error - Et is 12%
40

35

30

25

20

15

10

0
0 0.2 0.4 0.6 0.8 1 1.2

December 6, 2023 35
Using Three Intervals

• Use intervals (0.2,0.4),(0.4,0.6),(0.6,0.8):


– (n = 3, h = 0.2)
n −1
f (a ) + 2 f (a + ih ) + f (b )
I = (b − a ) i =1
2n
f (0.2 ) + 2 f (0.4 ) + f (0.6) + f (0.8)
= (0.8 − 0.2 )
(2)(3)
3.31 + 2(13.93 + 30.16) + 34.22
= 0.6
6
= 12.57
True value of integral is 12.82
December 6, 2023 36
Et is now 2%
40

35

30

25

20

15

10

0
0 0.2 0.4 0.6 0.8 1 1.2

December 6, 2023 37
Using Six Intervals

• Use intervals (0.2,0.3),(0.3,0,4), etc.


– (n = 6, h = 0.1)

f (0.2 ) + 2 f (0.3) + f (0.4 ) + f (0.5) + f (0.6) + f (0.7 ) + f (0.8)


I = (0.8 − 0.2 )
(2)(6)
3.31 + 2(7.34 + 13.93 + 22.18 + 30.16 + 35.22) + 34.22
= 0.6
12
= 12.76

True value of integral is 12.82


December 6, 2023 38
Et is now 0.5%
40

35

30

25

20

15

10

0
0 0.2 0.4 0.6 0.8 1 1.2

December 6, 2023 39
We will back with the same topic on the next week.
THANKS FOR YOUR ATTENTION

December 6, 2023 40
December 6, 2023 OSU/CSE 541 41
December 6, 2023 OSU/CSE 541 42
Multi-dimensional Integration

• Consider a two-dimensional case.


i 
1 1 1 n

 f ( x, y ) dxdy    Ai f  , y  dy
0 0 0 i =0 n 
i 
n 1
=  Ai  f  , y  dy
i =0 0 n 
n
 i j n
  Ai  Aj f  , 
i =0 j =0 n n
n
 i j
n
=  Ai A j f  , 
i =0 j =0 n n
December 6, 2023 OSU/CSE 541 43
Multi-dimensional Integration

• For the Trapezoid Rule, this leads to weights in the


following pattern:
1 1 2 2 2 2 2 1
2 2 4 4 4 4 4 2 1 i  0, n j  0, n

2 2 4 4 4 4 4 2 1 2 i  1, , n − 2 j  1, n − 1
Aij = 2 
2 2 4 4 4 4 4 2
4n  2 i  {1, n − 1} j  1, , n − 1
4 i  1, , n − 2 j  1, , n − 2
2 2 4 4 4 4 4 2
2 2 4 4 4 4 4 2 
1 1 2 2 2 2 2 1

1 2 2 2 2 2 1

December 6, 2023 OSU/CSE 541 44


Multi-dimensional Integration

• If we use the weights from the Trapezoid rule, the error is


still O(h2).
• However, there are now n2 function evaluations.
– Equally-spaced samples on a square region.

December 6, 2023 OSU/CSE 541 45


Multi-dimensional Integration
• In general, given k dimensions, we have
N= nk function evaluations:
 2
  − 
2
O ( h 2 ) = O ( n −2 ) = O  ( n k ) k  = O  N k 

   
• If the dimension is high, this leads to a significant amount
of additional work in going from h→h/2.
– Remember this for Monte-Carlo Integration.

December 6, 2023 OSU/CSE 541 46


Reducing the Error

• To improve the estimate of the integral, we can either:


– Add more intervals
– Use a higher order polynomial
– Use Richardson Extrapolation to examine the limit as h→0.
• Called Romberg Integration

December 6, 2023 OSU/CSE 541 47


Adding More Intervals

• If we have an estimate for one value of h, do we need to


recompute everything for a value of h/2?

h n −1

I h =  f ( a ) + 2 f ( a + ih ) + f ( b )
2 i =1 

December 6, 2023 OSU/CSE 541 48


Adding More Intervals

• This is called the Recursive Trapezoid Rule in the book.


• We have n→ 2n and h→h/2.

h 2 n −1
 h 
I h =  f (a) + 2  f  a + i  + f (b) 
2 4 i =1  2 
h n −1 n −1
 h 
=  f (a) + 2 f ( a + ih ) + 2 f  a + ih +  + f (b) 
4 i =1 i =0  2 
I h h  n −1  h 
= +  2 f  a + ih +  
2 4  i =0  2 
December 6, 2023 OSU/CSE 541 49
Recall Richardson Extrapolation

• Given two numerical estimates obtained using different h’s,


compute higher-order estimate
• Starting with a step size h1, the exact value is

A= A
• Suppose we reduce + Oto
n
step
(h1 )size (hh1 2)

A = A(h2 ) + O (h2 )
n

December 6, 2023 OSU/CSE 541 50


Richardson Extrapolation

• Multiplying the 2nd n


eqn by (h1/h2) and subtracting from the
1st eqn:
n
 h1 
  A( h2 ) − A(h1 )
A=  h2 
n
 h1 
  − 1
 h2 
• The new error term is generally O(h1n+1) or O(h1n+2).

December 6, 2023 OSU/CSE 541 51


Richardson Extrapolation

• The true integral value can be written


I = I (h ) + E (h )
• This is true for any iteration
I = I (h1 ) + E (h1 ) = I (h2 ) + E (h2 )

December 6, 2023 OSU/CSE 541 52


Richardson Extrapolation

• For example: Using (n = 2)


E  ch 2 f  [error = O(h2)]

order of error in
• where c is a constant trapezoidal rule
• Therefore:
E (h1 ) h1
2
 2
E (h2 ) h2
December 6, 2023 OSU/CSE 541 53
Richardson Extrapolation

• This leads to:


2
E (h1 )  E (h2 )
h 1
2
h 2

• For integration, we have:


2
I (h1 ) + E (h2 )  I (h2 ) + E (h2 )
1h
2
2h

December 6, 2023 OSU/CSE 541 54


Richardson Extrapolation

• Solving for E(h2):


I (h1 ) − I (h2 )
E (h2 )  2
h1
1− 2
h2
• And plugging back into the estimated integral.

I = I (h2 ) + E (h2 )
December 6, 2023 OSU/CSE 541 55
Richardson Extrapolation

• Leads to:
I  I (h2 ) +
1
I (h2 ) − I (h1 )
(h1 / h2 ) − 1
2

• Letting h2 = h1 /2
I  I (h2 ) + 2
1
I (h2 ) − I (h1 )
2 −1
I  I (h2 ) − I (h1 )
4 1
3 3
December 6, 2023 OSU/CSE 541 56
Romberg Integration

• We combined two O(h2) estimates to get an O(h4) estimate.


• Can also combine two O(h4) estimates to get an O(h6)
estimate.

I  I (hm ) − I (hl )
16 1
15 15

December 6, 2023 OSU/CSE 541 57


Romberg Integration

• Greater weight is placed on the more accurate estimate.


• Weighting coefficients sum to unity
– i.e, (16-1)/15=1
• Can continue, by combining two O(h6) estimates to get an
O(h8) estimate.

I (hm ) − I (hl )
64 1
I
63 63
December 6, 2023 OSU/CSE 541 58
Romberg Integration

• General pattern is called Romberg Integration


4k I j ,k − I j −1,k
I j ,k +1 
4 −1
k
= I j ,k + k
1
4 −1
( I j ,k − I j −1,k )

– j : level of subdivision, j+1 has more intervals.


– k : level of integration, k = 1 is original trapezoid
estimate [O(h2)], k = 2 is improved [O(h4)], etc.

December 6, 2023 OSU/CSE 541 59


Romberg Integration

• For example, j = 1, k = 1 leads to


4 I1,0 − I 0,0 4  h1  1
I1,1 =  I   − I ( h1 )
3 3 2 3

December 6, 2023 OSU/CSE 541 60


Example

• Consider the function:


f ( x ) = 0.2 + 25x − 200x 2 + 675x 3 − 900x 4 + 400x 5

• Integrate from a = 0 to b = 0.8


• Using the trapezoidal rule yields the following results:

December 6, 2023 OSU/CSE 541 61


Example

• Trapezoid Rules:
k=0 k=1
k intervals h Integral
j j=0 1 0.8 0.1728
j=1 2 0.4 1.0688
j=2 4 0.2 1.4848
4 1
I = (1.0688) − (0.1728) = 1.3674667
3 3 (j=1, k=1)
Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 62
Example

k=0 k=1
k
j segments h O (h 2 ) O (h 4 )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848

4 1
I = (1.4848) − (1.0688) = 1.62346667 (j=2, k=1)
3 3
Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 63
Example

k=1 k=2
k
segments h O (h 2 ) O (h 4 )
j
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848 1.62346667

16 1
(j=2, k=2) I = 15 (1.62346667) − 15 (1.3674667) = 1.64053334

Exact integral is 1.64053334


December 6, 2023 OSU/CSE 541 64
Example

k k=1 k=2 k=3


j segments h O( h 2 ) O( h 4 ) O( h6 )
1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848 1.62346667 1.64053334

December 6, 2023 OSU/CSE 541 65


122290012_Fabianus Arta Legawa
1,623876667 – 1,64923599 = 1,62319578
Example
SAP 122 094 Riril Astrit Shahaya

• Better and better results can be obtained by continuing this

k k=3

j segments h O(h 2 ) O(h 4 ) O(h 6 ) O ( h8 )


1 0.8 0.1728
2 0.4 1.0688 1.3674667
4 0.2 1.4848 1.62346667 1.64053334
8 0.1 ?? ?? ?? ??
64 1 (j=3, k=3)
I= (??) − (1.64053334) = ??
63 63
December 6, 2023 OSU/CSE 541 66
Romberg Integration
• Is this that significant?
• Consider the cost of computing the Trapezoid Rule for 1000
data points.
– Refinement would lead to 2000 data points.
• Implies an additional 1003 operations using the Recursive Trapezoid
Rule.
• Not to mention the 1000 (expensive) function evals.
– Romberg Integration cost:
• Three additional operations – no function evals!!!

December 6, 2023 OSU/CSE 541 67


Higher-Order Polynomials

• Recall:
xn x0+m1 x0+m1+m2 xn
 x0
f ( x)dx = 
x0
pm1 ( x)dx + 
x0+ m1
pm2 ( x)dx + ... + 
xn−mn
pmn ( x)dx

m Polynomial Formula Error


1 linear Trapezoid O(h 2 )
2 quadratic Simpson' s 1/3 O(h 4 )
3 cubic Simpson' s 3/8 O(h 4 )

December 6, 2023 OSU/CSE 541 68


Simpson’s 1/3 Rule

• If we use a 2nd order polynomial (need 3 points or 2


intervals):
 x + x2 
– Lagrange form.  x1 = 0 
 2 

 ( x − x1 )( x − x2 ) (x − x0 )(x − x2 ) f (x )
f ( x0 ) +
x2
I = 
x0 ( x − x )( x − x ) ( − )( − ) 1
 0 1 0 2 x1 x0 x1 x 2

+
( x − x0 )( x − x1 ) 
f ( x2 )dx
(x2 − x0 )(x2 − x1 ) 

December 6, 2023 OSU/CSE 541 69


Simpson’s 1/3 Rule

• Requiring equally-spaced intervals:


 ( x − x0 − h )( x − x0 − 2h ) ( x − x0 )( x − x0 − 2h )
f ( x0 ) + f ( x1 )
x2
I = 
x0
 −h ( −2h ) ( h )( −h )
+
( x − x0 )( x − x0 − h ) 
f ( x2 )  dx
( 2h )( h ) 

December 6, 2023 OSU/CSE 541 70


Simpson’s 1/3 Rule

• Integrate and simplify:


b−a
I   f (x0 ) + 4 f ( x1 ) + f (x2 )
h
h=
12 3 2
10

Quadratic
8 Polynomial

0
3 5 7 9 11 13 15

December 6, 2023 OSU/CSE 541 71


Simpson’s 1/3 Rule

• If we use a = x0 and b = x2, and


x1 = (b+a)/2

f (x0 ) + 4 f (x1 ) + f (x2 )


I  (b − a )
6
width
average height

December 6, 2023 OSU/CSE 541 72


Simpson’s 1/3 Rule

• Error for Simpson’s 1/3 rule

Et = −
h 5 (4 )
f ( ) = −
(b − a ) (4 )
5
f ( ) 4
90 2880
O(h )

b−a
h=
2

Integrates a cubic exactly: f (4 )


( ) = 0

December 6, 2023 OSU/CSE 541 73


Composite Simpson’s 1/3 Rule

• As with Trapezoidal rule, can use multiple applications of


Simpson’s 1/3 rule.
• Need even number of intervals
– An odd number of points are required.

December 6, 2023 OSU/CSE 541 74


Composite Simpson’s 1/3 Rule

• Example: 9 points, 4 intervals


25

20

15

10

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5

-5

December 6, 2023 OSU/CSE 541 75


Composite Simpson’s 1/3 Rule

• As in composite trapezoid, break integral up into n/2 sub-


integrals:
I =  f (x )dx +  f (x )dx + ... +  f (x )dx
x 2 x 4 x n

x 0 x 2 x n −2

• Substitute Simpson’s 1/3 rule for each integral and collect


terms.
n −1 n−2
f ( x0 ) + 4  f ( xi ) + 2  f (x )+ f (x )
j n

I = (b − a )
i =1,3,5 j = 2,4,6

3n
n+1 data points, an odd number
December 6, 2023 OSU/CSE 541 76
Composite Simpson’s 1/3 Rule

• Odd coefficients receive a weight of 4, even receive a


weight of 2.
• Doesn’t seem very fair, does it?

4 1 coefficients on
1
4 1 i=n numerator
1 1
1 4
i=0

December 6, 2023 OSU/CSE 541 77


Error Estimate
• The error can be estimated by:
nh5 ( 4 ) (b − a )h 4 ( 4 ) 4
Ea = f = f O(h )
180 180
• If n is doubled, h → h/2 and Ea → Ea/16

f ( 4 ) is the average 4th derivative

December 6, 2023 OSU/CSE 541 78


Example
− x2
• Integrate x) = ea = 0 to b = 2.
f (from
• Use Simpson’s 1/3 rule:
b−a a+b
h= =1 x0 = a = 0 x1 = =1 x2 = b = 2
2 2
1
dx  h  f ( x0 ) + 4 f ( x1 ) + f ( x2 ) 
2
I = e − x2
0 3
1
=  f ( 0 ) + 4 f (1) + f ( 2 ) 
3
1 0
= (e + 4e −1 + e −4 ) = 0.82994
3
December 6, 2023 OSU/CSE 541 79
Example

• Error estimate: Et = −
h 5 (4 )
f ( )
90

• Where h = b - a and a <  < b


• Don’t know 
– use average value
5
1 ( 4) 1 5f ( 4)
( x0 ) + f ( 4)
( x1 ) + f ( 4)
( x2 )
Et  Ea = − f =−
90 90 3

December 6, 2023 OSU/CSE 541 80


Another Example

• Let’s look at the polynomial again:


f ( x ) = 0.2 + 25x − 200x 2 + 675x 3 − 900x 4 + 400x 5
– From a = 0 to b = 0.8
b−a a+b
h= = 0.4 x0 = a = 0 x1 = = 0.4 x2 = b = 0.8
2 2

I =  f ( x )dx  h f ( x0 ) + 4 f ( x1 ) + f ( x2 )
2 1
0 3
=
( 0.4 )
 f (0) + 4 f (0.4) + f (0.8)
3
= 1.36746667
Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 81
Error

• Actual Error: (using the known exact value)


E = 1.64053334- 1.36746667 = 0.27306666 16%

• Estimate error: (if the exact value is not


available)
h 5 (4 )
Et = − f ( )
90
• Where a <  < b.

December 6, 2023 OSU/CSE 541 82


Error

• Compute the fourth-derivative


f ( 4)
( x ) = −21600 + 48000x

0.4 5 0.45
Et  Ea =− f (4 )
( x1 ) = − f (4 )
(0.4 ) = 0.27306667
90 90

middle point

• Matches actual error pretty well.


December 6, 2023 OSU/CSE 541 83
Example Continued
• If we use 4 segments instead of 1: h=
b−a
= 0.2
– x = [0.0 0.2 0.4 0.6 0.8] n
f (0) = 0.2 f (0.2) = 1.288 f (0.4) = 2.456
f (0.6) = 3.464 f (0.8) = 0.232
n −1 n −2
f ( x0 ) + 4  f (x ) + 2  f (x ) + f (x )
i j n

I = (b − a ) i =1, 3, 5 j =2, 4,6

3n
f (0) + 4 f (0.2) + 2 f (0.4) + 4 f (0.6) + f (0.8)
= (0.8 − 0)
(3)( 4)
0.2 + 4(1.288 + 3.464) + 2( 2.456) + 0.232
= 0.8
12
= 1.6234667 Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 84
Error

• Actual Error: (using the known exact value)


E = 1.64053334- 1.6234667 = 0.01706667 1%

• Estimate error: (if the exact value is not available)

0.25 (4 ) 0.25 (4 )
Et  Ea = − f ( x2 ) = − f (0.4) = −0.0085
90 90
middle point

December 6, 2023 OSU/CSE 541 85


Error

• Actual is twice the estimated, why?


• Recall:
f ( 4)
( x ) = −21600 + 48000x

max
x 0,0.8 
 f ( 4)
( x) = f ( 4)
(0) = −21600

f ( 4)
(0.4) = 2400

December 6, 2023 OSU/CSE 541 86


Error

• Rather than estimate, we can bound the absolute value of


the error:
0.25 ( 4) 0.25 ( 4)
Ea = − f ( )  f ( 0 ) = 0.0768
90 90

• Five times the actual, but provides a safer error metric.

December 6, 2023 OSU/CSE 541 87


Simpon’s 1/3 Rule
• Simpson’s 1/3 rule uses a 2nd order polynomial
– need 3 points or 2 intervals
– This implies we need an even number of intervals.
• What if you don’t have an even number of intervals? Two choices:
1. Use Simpson’s 1/3 on all the segments except the last (or first) one, and use
trapezoidal rule on the one left.
– Pitfall - larger error on the segment using trapezoid
2. Use Simpson’s 3/8 rule.

December 6, 2023 OSU/CSE 541 88


Simpson’s 3/8 Rule
• Simpson’s 3/8 rule uses a third order polynomial
– need 3 intervals (4 data points)

f ( x)  p3 ( x) = a0 + a1 x + a2 x 2 + a3 x 3

I =  f (x )dx   p3 (x )dx
x3 x3

x0 x0

December 6, 2023 OSU/CSE 541 89


Simpson’s 3/8 Rule
• Determine a’s with Lagrange polynomial
• For evenly spaced points

I = h f (x0 ) + 3(x1 ) + 3 f (x2 ) + f (x3 )


3
8

b−a
h=
3

December 6, 2023 OSU/CSE 541 90


Error

• Same order as 1/3 Rule.


– More function evaluations.
– Interval width, h, is smaller.
3 5 ( 4)
Et = − h f ( ) O(h 4 )
80

• Integrates a cubic exactly:


 f (4 ) ( ) = 0

December 6, 2023 OSU/CSE 541 91


Comparison
• Simpson’s 1/3 rule and Simpson’s 3/8 rule have the same order of
error
– O(h4)
– trapezoidal rule has an error of O(h2)
• Simpson’s 1/3 rule requires even number of segments.
• Simpson’s 3/8 rule requires multiples of three segments.
• Both Simpson’s methods require evenly spaced data points

December 6, 2023 OSU/CSE 541 92


Mixing Techniques
• n = 10 points  9 intervals
– First 6 intervals - Simpson’s 1/3
– Last 3 intervals - Simpson’s 3/8

Simpson’s 1/3

Simpson’s 3/8

December 6, 2023 OSU/CSE 541 93


Newton-Cotes Formulas

• We can examine even higher-order polynomials.


– Simpson’s 1/3 - 2nd order Lagrange (3 pts)
– Simpson’s 3/8 - 3rd order Lagrange (4 pts)
• Usually do not go higher.
• Use multiple segments.
– But only where needed.

December 6, 2023 OSU/CSE 541 94


Adaptive Simpson’s Scheme

• Recall Simpson’s 1/3 Rule:


I   f (x0 ) + 4 f ( x1 ) + f (x2 )
h
3

• Where initially, we have a=x0 and b=x2.


• Subdividing the integral into two:
h
I   f ( a ) + 4 f ( x1 ) + 2 f ( x2 ) + 4 f ( x3 ) + f ( b ) 
6

December 6, 2023 OSU/CSE 541 95


Adaptive Simpson’s Scheme

• We want to keep subdividing, until we reach a desired error


tolerance, .
• Mathematically:
h 
b

 f ( x ) dx −   f ( a ) + 4 f ( x1 ) + f ( b )    
a 3 
h 
b

 f ( x ) dx −   f ( a ) + 4 f ( x1 ) + 2 f ( x2 ) + 4 f ( x3 ) + f ( b )    
a 6 

December 6, 2023 OSU/CSE 541 96


Adaptive Simpson’s Scheme
• This will be satisfied if:
h  
c

 f ( x ) dx −   f ( a ) + 4 f ( x1 ) + f ( x2 )    , and
a 6  2
h  
b

 f ( x ) dx −   f ( x2 ) + 4 f ( x3 ) + f ( b )    , where
c 6  2
a+b
c = x2 =
2
• The left and the right are within one-half of the error.

December 6, 2023 OSU/CSE 541 97


Adaptive Simpson’s Scheme

• Okay, now we have two separate intervals to integrate.


• What if one can be solved accurately with an h=10-3, but the
other requires many, many more intervals, h=10-6?

December 6, 2023 OSU/CSE 541 98


Adaptive Simpson’s Scheme

• Adaptive Simpson’s method provides a divide and conquer


scheme until the appropriate error is satisfied everywhere.
• Very popular method in practice.
• Problem:
– We do not know the exact value, and hence do not know the
error.

December 6, 2023 OSU/CSE 541 99


Adaptive Simpson’s Scheme

• How do we know whether to continue to subdivide or


terminate?
b
I   f ( x ) dx = S ( a, b ) + E ( a, b ) , where
a

b−a   a+b 
S ( a, b ) =  f (a) + 4 f   + f ( b )  , and
6   2  
1  b − a  ( 4)
5

E ( a, b ) = −   f
90  2 

December 6, 2023 OSU/CSE 541 100


Adaptive Simpson’s Scheme

• The first iteration can then be defined as:


I = S ( ) + E ( ) , where
1 1

S ( ) = S ( a, b ) , E ( ) = E ( a, b )
1 1

• Subsequent subdivision can be defined as:


S ( 2)
= S ( a, c ) + S ( c, b )

December 6, 2023 OSU/CSE 541 101


Adaptive Simpson’s Scheme

• Now, since
E ( 2)
= E ( a , c ) + E ( c, b )
• We can solve for E(2) in terms of E(1).
5 5
1  h / 2  ( 4) 1  h / 2  ( 4)
E(
2)
=−   f −   f
90  2  90  2 
5
 1  1  h  ( 4) 1 (1)
= 4 −   f = E
 2  90  2  16

December 6, 2023 OSU/CSE 541 102


Adaptive Simpson’s Scheme

• Finally, using the identity:


(1) (1) ( 2) ( 2)
I =S +E =S +E
• We have:
( 2) (1) (1) ( 2) ( 2)
S −S = E −E = 15 E
• Plugging into our definition:

I =S ( 2)
+E ( 2)
=S ( 2)
+
1 ( 2)
15
S −S((1)
)
December 6, 2023 OSU/CSE 541 103
Adaptive Simpson’s Scheme

• Our error criteria is thus:


I −S =( 2)
15
(
1 ( 2)
S −S (1)
 )
• Simplifying leads to the termination formula:

(S ( 2)
−S (1)
)  15
December 6, 2023 OSU/CSE 541 104
Adaptive Simpson’s Scheme

• What happens graphically:

December 6, 2023 OSU/CSE 541 105


S2 − S1  15 → subdivide

December 6, 2023 OSU/CSE 541 106


December 6, 2023 OSU/CSE 541 107

S2 − S1  15 → subdivide
2

December 6, 2023 OSU/CSE 541 108



S2 − S1  15 → done
4
1
I = S2 + ( S2 − S1 )
15

December 6, 2023 OSU/CSE 541 109



S2 − S1  15 → subdivide
4

December 6, 2023 OSU/CSE 541 110


1
I = S2 + ( S2 − S1 )
15

December 6, 2023 OSU/CSE 541 111


1
I = S2 + ( S2 − S1 )
15

December 6, 2023 OSU/CSE 541 112


Iright =Ileft + Iright

I=Ileft + Iright

December 6, 2023 OSU/CSE 541 113


December 6, 2023 OSU/CSE 541 114
December 6, 2023 OSU/CSE 541 115
Adaptive Simpson’s Scheme

• We gradually capture the difficult spots.

December 6, 2023 OSU/CSE 541 116


Guassian Quadrature
• Idea is that if we evaluate the function at certain points, and sum
with certain weights, we will get a more accurate integral
• Evaluation points and weights are pre-computed and tabulated
• Basic form:
n
I =  f ( x)dx   ci f ( xi )
1

−1
i =1

ci : weighting factors
xi : sampling points selected optimally New!!

December 6, 2023 OSU/CSE 541 119


Guassian Quadrature
• Note that the interval is between –1 and 1
• For other intervals, a change of variables is used to transfer the
problem so that it utilizes the interval [-1, 1]
• This is a linear transform, such that for t[a,b]:
b
a f (t )dt
• We have for x[-1,1]:

(b − a) x + b + a 2t − b − a
t= x=
2 b−a
December 6, 2023 OSU/CSE 541 120
Guassian Quadrature
• As t = a  x = -1
• As t = b  x = 1
(b − a)
dt = dx
2
 (b − a) x + b + a 
f (t ) = f  
 2 
b (b − a) 1  (b − a) x + b + a 
a f (t )dt = 2 −1 f  2
dx

December 6, 2023 OSU/CSE 541 121
Guassian Quadrature
• Basic form of Gaussian quadrature:
n
I =  f ( x)dx   ci f ( xi )
1

−1
i =1

• For n=2, we have:


I  c1 f ( x1 ) + c2 f ( x2 )
• This leads to 4 unknowns: c1, c2, x1, and x2
– two unknown weights (c1, c2)
– two unknown sampling points (x1, x2)
December 6, 2023 OSU/CSE 541 122
Guassian Quadrature

• What we need now, are four known values for the equation.
• If we had these, we could then attempt to solve for the four
unknowns.
• Let’s make it work for polynomials!!!

December 6, 2023 OSU/CSE 541 123


Guassian Quadrature
• In particular, let’s look at these simple polynomials:
– Constant
• f(x)=1
– Linear
• f(x)=x
– Quadratic
• f(x)=x2
– Cubic
• f(x)=x3

December 6, 2023 OSU/CSE 541 124


Guassian Quadrature
• Recalling the formula: I  c1 f ( x1 ) + c2 f ( x2 )
– Constant
= c1 f (x1 ) + c2 f (x2 ) = c1 + c2
1

• f(x)=1  1dx = 2
−1

= c1 f (x1 ) + c2 f ( x2 ) = c1 x1 + c2 x2
– Linear 1

• f(x)=x  xdx = 0
−1

– Quadratic
−1x dx = 3 = c1 f (x1 ) + c2 f (x2 ) = c1 x1 + c2 x2
1
2 2 2 2
• f(x)=x2
– Cubic
x 3 dx = 0 = c1 f (x1 ) + c2 f (x2 ) = c1 x1 + c2 x2
1

3 3
• f(x)=x3 −1

December 6, 2023 OSU/CSE 541 125


Guassian Quadrature

• We can now solve for our unknowns:


– Note, this is not an easy problem and will not be covered in this class.

c1 = c2 = 1
1
x1 = − = −0.577
3
1
x2 = = 0.577
3

December 6, 2023 OSU/CSE 541 126


Guassian Quadrature

• This yields the two point Gauss-Legendre formula

 1   1 
I  f − + f  
 3  3

December 6, 2023 OSU/CSE 541 127


Guassian Quadrature

• This is exact for all polynomials up to and including degree


3 (cubics).
1 1 1 1 1

 ( ax + bx + cx + d )dx = a  x dx + b  x dx + c  xdx + d  dx
3 2 3 2

−1 −1 −1 −1 −1

  −1 3  1 3    −1  2  1  2    −1   1  
= a +  + b + +c + + d (1 + 1)
  3   3     3   3     3   3  
   

( ax +bx +cx+d )
1
3 2 3
=
−1
3

December 6, 2023 OSU/CSE 541 128


Guassian Quadrature
1

−1
f ( x)dx  f (−0.577) + f (0.577)
f(x)
f(-0.577)
f(0.577)

-0.577 0.577
x
-1 1
December 6, 2023 OSU/CSE 541 129
Example
• Integrate f(x) from a = 0 to b = 0.8
f ( x ) = 0.2 + 25x − 200x 2 + 675x 3 − 900x 4 + 400x 5
• Transform from [0, 0.8] to [-1, 1]
b (b − a ) 1  (b − a ) x + b + a 
a
f (t )dt =
2 −1
f
 2


dx

0.8 (0.8 − 0) 1  (0.8 − 0)t + 0.8 + 0 


I = f ( x )dx =  f dt
0 2 −1
 2 
= 0.4  f (0.4t + 0.4 )dt
1

−1
December 6, 2023 OSU/CSE 541 130
Example

• Solving
I = 0.4  f (0.4t + 0.4 )dt
1

−1

1 0.2 + 25(0.4t − 0.4) − 200(0.4t − 0.4)2 


= 0.4   5
dt
+ 675(0.4t − 0.4) − 900(0.4t − 0.4) + 400(0.4t − 0.4) 
−1 3 4

• And substituting for the 2-point formula:


I = 0.4  f (t )dt
1

−1 t = 1 / 3
I  0.51674055+ 1.30583723= 1.82257778
Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 131
Higher-order Gaussian Quadrature

• Recall the basic form:


n
I =  f ( x)dx   ci f ( xi )
1

−1
i =1

• Let’s look at n=3.


I  c1 f (x1 ) + c2 f (x2 ) + c3 f (x3 )
• We now have 6 unknowns: c1, c2, c3,x1, x2, and x3
– three unknown weights (c1, c2 , c3)
– three unknown sampling points (x1, x2 , x3)

December 6, 2023 OSU/CSE 541 132


Use 6 equations - constant, linear, quadratic, cubic,
4th order and 5th order to find those unknowns

= c1 f ( x1 ) + c2 f ( x2 ) + c3 f ( x3 ) = c1 + c2 + c3
1
 1dx = 2
−1

= c1 f ( x1 ) + c2 f ( x2 ) + c3 f ( x3 ) = c1 x1 + c2 x2 + c3 x3
1
 xdx = 0
−1

2
( ) ( ) ( )
1
−1 = = + + = + +
2 2 2 2
x dx c1 f x1 c2 f x 2 c3 f x3 c x
1 1 c x
2 2 c x
3 3
3
x 3dx = 0 = c1 f ( x1 ) + c2 f ( x2 ) + c3 f ( x3 ) = c1 x1 + c2 x2 + c3 x3
1

3 3 3
−1

2
( ) ( ) ( )
1
−1 = = + + = + +
4 4 4 4
x dx c1 f x1 c2 f x 2 c3 f x3 c x
1 1 c x
2 2 c x
3 3
5
x 5dx = 0 = c1 f ( x1 ) + c2 f ( x2 ) + c3 f ( x3 ) = c1 x1 + c2 x2 + c3 x3
1

5 5 5
−1

December 6, 2023 OSU/CSE 541 133


Higher-order Gaussian Quadrature

• Can solve these equations (or have some one smarter than us, like
Guass solve them).
c1 = 5 / 9 c2 = 8 / 9 c3 = 5 / 9
x1 = − 3 / 5 = −0.77459669 x2 = 0 x2 = 3 / 5 = 0.77459669

• Produces the three point Gauss-Legendre formula


I  c1 f (x1 ) + c2 f (x2 ) + c3 f (x3 )
– Exact for polynomials up to and including degree 5
(because using 5th degree polynomial)

December 6, 2023 OSU/CSE 541 134


Higher-order Gaussian Quadrature
1 5 8 5
−1 f ( x)dx  9 f (−0.775) + 9 f (0.0) + 9 f (0.775)
f(-0.775)
f(0)
f(0.775)

x
-0.775 0.775
December 6, 2023 -1 OSU/CSE 541 1 135
Example

f ( x ) = 0.2 + 25x − 200x 2 + 675x 3 − 900x 4 + 400x 5


Integrate from a = 0 to b = 0.8
Transform from [0, 0.8] to [-1, 1]
f ( x )dx
0.8
I = replace -0.4 with +0.4
0

1 0.2 + 25(0.4t − 0.4) − 200(0.4t − 0.4) 2 


=  5
dt
 + 675(0.4t − 0.4) − 900(0.4t − 0.4) + 400(0.4t − 0.4) 
−1 3 4

December 6, 2023 OSU/CSE 541 136


Example

• Using the 3-point Gauss-Legendre formula:

 3 8  3
+ f (0) +
5 5
I 
f −  f  
9 
5 9 9 5 
  

Substitute into the transform equation and get

I  0.281301290+ 0.873244444+ 0.485987599


= 1.64053334
Exact integral is 1.64053334
December 6, 2023 OSU/CSE 541 137
Gaussian Quadrature

Can develop higher order Gauss-Legendre forms


using
I  c1 f (x1 ) + c2 f (x2 ) + ... + cn f (xn )

Values for c’s and x’s are tabulated


Use the same transformation to map interval onto
[-1, 1]

December 6, 2023 OSU/CSE 541 138


I =  f ( x)dx  c1 f (x1 ) + c2 f (x2 ) + ... + cn f (xn )
1

−1

n 2 3 4 5 6
ci 1.0 0.5555555556 0.3478548451 0.2369268850 0.1713245
1.0 0.8888888889 0.6521451549 0.4786286705 0.3607616
0.5555555556 0.6521451549 0.5688888889 0.4679139
0.3478548451 0.4786286705 0.4679139
0.2369268850 0.3607616
0.1713245

− 0.5773502692 − 0.7745966692 − 0.8611363116 − 0.9061798459 − 0.932469514


0.5773502692 0.0000000000 − 0.3399810436 − 0.5384693101 − 0.661209386
xi 0.7745966692 0.3399810436 0.0000000000 − 0.238619186
0.8611363116 0.5384693101 0.238619186
0.9061798459 0.661209386
0.932469514
December 6, 2023 OSU/CSE 541 139
December 6, 2023 OSU/CSE 541 140
December 6, 2023 OSU/CSE 541 141
December 6, 2023 OSU/CSE 541 144
December 6, 2023 OSU/CSE 541 145
December 6, 2023 OSU/CSE 541 146
December 6, 2023 OSU/CSE 541 147
December 6, 2023 OSU/CSE 541 148
December 6, 2023 OSU/CSE 541 149

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