Numerical Integration of A Function
Numerical Integration of A Function
resulting in
1 1
z0 = − ; z1 = ; c0 = 1; c1 = 1
3 3
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
∫ (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
Wi =
(
2 1− z 2
i )
[(n + 1)Pn (zi )]2
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
e − ( z / 2+1.5 )
1
Iz = ∫ dz (T.V. = 0.571946)
−1 1 − z (z / 2 + 1.5)
2
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
resulting in Iz=0.571833
• Error in Iz= 1.13x10−4
Numerical Integration: Improper Integrals
b
• 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
∫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