0% found this document useful (0 votes)
13K views23 pages

Numerical Integration of A Function

1) Gauss quadrature provides a numerical method to approximate definite integrals using a weighted sum of function values. 2) It works by approximating the integral of a function as a linear combination of the function evaluated at specific points. 3) The document discusses Gauss-Legendre and Gauss-Tchebycheff quadrature rules, including how to determine the optimal points and weights to use in the approximation.

Uploaded by

Abhishek Arya
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)
13K views23 pages

Numerical Integration of A Function

1) Gauss quadrature provides a numerical method to approximate definite integrals using a weighted sum of function values. 2) It works by approximating the integral of a function as a linear combination of the function evaluated at specific points. 3) The document discusses Gauss-Legendre and Gauss-Tchebycheff quadrature rules, including how to determine the optimal points and weights to use in the approximation.

Uploaded by

Abhishek Arya
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/ 23

Numerical Integration of a Function

• If we evaluate the function at 2 points, what


should be the location of these points such
that the error is minimized?
1
• Standard domain ~
∫ f ( z )dz ≈ I z = c0 f ( z0 ) + c1 f (z1 )
−1

• Four adjustable parameters, c0, z0 and c1, z1


• May integrate polynomials of degree 3 exactly
• How to obtain these parameters?
• One option: Using f(z) as 1,z,z2,z3
Integration of a Function: Standard Domain
• We get:
2
c0 + c1 = 2; c0 z0 + c1 z1 = 0; c z + c z = ; c0 z03 + c1 z13 = 0
2
0 0
2
1 1
3

resulting in
1 1
z0 = − ; z1 = ; c0 = 1; c1 = 1
3 3

• 2-point Gauss Quadrature


General Methodology
• Let the exactly integrable polynomial be
z − z1 z − z0
f3 ( z) = f ( z0 ) + f ( z1 ) + (a + bz )( z − z0 )( z − z1 )
z0 − z1 z1 − z0

a and b are arbitrary constants


• This function satisfies
f 3 ( z0 ) = f ( z0 ) and f 3 ( z1 ) = f ( z1 )
3.0

2.0

1.0

0.0
-1 -0.5 0 0.5 1

1
~
∫ f ( z )dz ≈ I z = c0 f ( z0 ) + c1 f ( z1 )
−1

z − z1 z − z0
f3 ( z) = f ( z0 ) + f ( z1 )
z0 − z1 z1 − z0
+ (a + bz )( z − z0 )( z − z1 )
Gauss Quadrature: General Form
• Since the cubic polynomial is exactly integrable
1
z − z1 z − z0
∫−1 z0 − z1 f ( z0 ) + z1 − z0 f ( z1 ) + (a + bz)( z − z0 )( z − z1 )dz
= c0 f ( z0 ) + c1 f ( z1 )
1 1
z − z1 z − z0
Which implies that c0 = ∫ dz and c1 = ∫ dz
z − z1
−1 0
z − z0
−1 1

And, for any arbitrary a and b:


1

∫ (a + bz )( z − z )( z − z )dz = 0
−1
0 1
Gauss-Legendre Quadrature
• Recall the first few Legendre polynomials:
P0(x)=1; P1(x) = x; P2(x) = (−1+3x2)/2
P3(x) = (−3x+5x3)/2; P4(x) = (3−30x2+35x4)/8
• Any of these is orthogonal to all lower degree
polynomials. Earlier we had seen that P2(z) is
orthogonal to P0(z), and P1(z), i.e.,
1 1

∫ P ( z ) P ( z )dz = ∫ P ( z ) P ( z )dz = 0
−1
2 0
−1
2 1

• It implies that P2(z) is orthogonal to 1 and z


Gauss-Legendre Quadrature
• Therefore, if we want the quadratic (z-z0)(z-z1)
to be orthogonal to all linear functions, we
should choose z0 and z1 as the roots of
(−1+3z2)=0
• Which gives us −1/√3, and 1/√3
• The weights are obtained from
1 1
z− 1
1 z+
1
3  z 3 2  3 dz = 1
c0 = ∫ dz =  − z  = 1 and c1 = ∫
−1 −
1 1 2 4  −1 1 1
− −1 +
3 3 3 3
Gauss-Legendre Quadrature
• Similarly, for three Gauss points, we need the
3
zeroes of (−3z+5z ), which are 0, ±
3
 3  5
z  z − 
5  5 3 5 2 5 2 5 3 5 2
L0 ( z ) =  =− z + z ; L1 ( z ) = 1 − z ; L2 (z ) = z+ z
3 3 6 5 6 3 6 5 6
×2
5 5
1
1
 5z 2
3 5 3 5 8 5
c0 = ∫ L0 ( z )dz = − + z  = ; c1 = ; c2 =
−1  12 5 18  −1 9 9 9
• Since the c’s are weights, it is common to use
the symbol, W
Gauss-Legendre Quadrature Weights
• The weights may be related to the Legendre
polynomials, Pn(z):

Wi =
(
2 1− z 2
i )
[(n + 1)Pn (zi )]2

• For example, with 3 Gauss points (n=2), P2(z)


= (−1+3z2)/2; the z’s are −√0.6, 0, √0.6
• The value of P2(z) at these points are 0.4, -0.5,
and 0.4, respectively.
• The weights are 5/9, 8/9, and 5/9, as before.
6.0

5.0

4.0

3.0

2.0

1.0

0.0
-1 -0.5 0 0.5 1

2 3 4 5
f ( x) = 1 + x + x + x + x + x
25.0

20.0

15.0

10.0

5.0

0.0
-1 -0.5 0 0.5 1

-5.0

2 3 4 5
f ( x) = 1 + 2 x + 3x + 4 x + 5 x + 6 x
Abscissa, Weight, and Error for the Gauss-Legendre Quadrature points

n Abscissa Weight Error


f " (ξ )
0 0.00000 2.0000
3
f iv (ξ )
1 ±0.57735 1.0000
135
0.00000 0.88889 f vi (ξ )
2
±0.77460 0.55556 15750
±0.33998 0.65215 f ( ) (ξ )
8
3
±0.86114 0.34785 3472875
0.00000 0.56889
f ( ) (ξ )
10
4 ±0.53847 0.47863
±0.90618 0.23693 1237732650
Weighted Gauss Quadrature
• Instead of integral of the function, we need
the integral with a weight-function
1
~ n
∫ w(z ) f ( z )dz ≈ I = ∑Wi f (zi )
−1 i =0

• Recall the Tchebycheff polynomials, where the


weight was 1 / 1 − z 2
• Using this weight function, we get the Gauss-
Tchebycheff quadrature
• Of course, we could treat w(z)f(z) as a single
function and use Gauss-Legendre quadrature
Gauss-Tchebycheff quadrature
• The quadrature points are the zeroes of
Tchebycheff polynomial of degree n+1
• These zeroes are given by

• And all the weights turn out to be equal to


π/(n+1)
Gauss Quadrature: Example
2
1
• Estimate I = ∫ xe x dx (T.V. = 0.170483)
1
• First, convert to standard domain: z=2(x−1.5)
• Use 2-point Gauss-Legendre:
i z W x f
0 −1/√3 1 1.5−1/2√3 0.245849
1 1/√3 1 1.5+1/2√3 0.093467

resulting in Iz=0.339315 and Ix=0.169658


• Error in Ix = 8.25x10−4. In Iz= 1.65x10−3
f (ζ )
iv
th derivative (z) varies from
• Recall: E = . 4
135
0.04 to 1.5. Theoretical error: 0.0003 to 0.011
Gauss Quadrature: Example
• Use 3-point Gauss-Legendre:
i z W x f

0 −√0.6 5/9 1.5−√0.6/2 0.295380

1 0 8/9 1.5 0.148753

2 √0.6 5/9 1.5+√0.6/2 0.080263

resulting in Iz=0.340916 and Ix=0.170458

• Error in Ix = 2.5x10−5. In Iz= 5x10−5


Gauss-Tchebycheff Quadrature: Example
• Estimate (same as before, but weighted)

e − ( z / 2+1.5 )
1
Iz = ∫ dz (T.V. = 0.571946)
−1 1 − z (z / 2 + 1.5)
2

• Use 2-point Gauss-Tchebycheff (n=1), T2(z) =


2z2−1; the z’s are ±√0.5:
i z W x f
0 −1/√2 π/2 1.5−1/2√2 0.277173
1 1/√2 π/2 1.5+1/2√2 0.084529

resulting in Iz=0.568160
• Error in Iz= 3.79x10−3
Gauss-Tchebycheff Quadrature: Example
• Use 3-points, T3(z) = 4z3−3z; the z’s are
−√0.75, 0,√0.75 :
i z W x f
0 −√0.75 π/3 1.5−√0.75/2 0.322444

1 0 π/3 1.5 0.148753

2 √0.75 π/3 1.5+√0.75/2 0.074863

resulting in Iz=0.571833
• Error in Iz= 1.13x10−4
Numerical Integration: Improper Integrals
b

• Estimate I = ∫ f ( x)dx for a known function


a

• We have assumed:
• a and b are finite
( ) is defined and is continuous in (a,b)
• f(x)
• Improper Integral: When any (or both) of
these assumptions is violated
1
• E.g., ∞ cos x
I = ∫e
−x 2
dx I =∫ dx
1 0 x
Improper Integrals: Convergence
• An improper integral may or may not
converge (i.e., have a finite value)
• We assume that it converges! How to find it?
• If the domain is unbounded, we use a
transformation of variable to make it finite
1

∞ 1 z2
− x2 1 e
I = ∫ e dx : z = ⇒ I = ∫ 2 dz
1
x 0
z
• If f(x) is undefined at one end, a semi-open
method could be used (or variable transform)
1 1
cos x
I =∫ dx : z = x ⇒ I = ∫ 2 cos z dz
2

0 x 0
Improper Integrals: Evaluation

• If f(x) is undefined at both ends, an open method


could be used
• If f(x) is undefined at some point within (a,b), we
may need to split the integral into two parts
• Sometimes both the domain and the range could
be unbounded. E.g.,

cos x
I =∫ dx
0 x
Improper Integrals: Example
• The complementary error function is defined

as 2 2

∫e
−t
erfc( x) = dt
π x
• Estimate the value of erfc(1) (T.V.=0.157299)
• Transformation: y=1/t 1

∞ 1 y2
2 e
I = ∫ e dt ⇒ I = ∫ 2 dy
−t

1 0
y
• Note that f(y) is undefined at y=0 (limit does
exist). Trapezoidal, Simpson… cannot be used!
• Use 3-point Gauss-quadrature
Improper Integrals: Example

• 3-point Gauss-quadrature
i z W y f

0 −√0.6 5/9 (−√0.6+1)/2 0.000000

1 0 8/9 0.5 0.073263

2 √0.6 5/9 (√0.6+1)/2 0.356644

• Iz=0.263258; Iy=0.131629; erfc(1)=0.148527


• Error = 8.77x10−3

You might also like