Numerical Methods in Engineering With Python 3
Numerical Methods in Engineering With Python 3
for any given value of x. Test the program by computing Si(1.0), and compare the
result with the tabulated value 0.946 08.
4 b
w(x)f (x)dx (6.15)
a
where w(x), called the weighting function, can contain singularities, as long as they
31
are integrable. An example of such integral is 0 (1 + x 2 ) ln x dx. Sometimes infinite
3 ∞ −x
limits, as in 0 e sin x dx, can also be accommodated.
Gaussian integration formulas have the same form as Newton-Cotes rules
n
I= A i f (xi ) (6.16)
i=0
where, as before, I represents the approximation to the integral in Eq. (6.15). The
difference lies in the way that the weights A i and nodal abscissas xi are determined. In
Newton-Cotes integration the nodes were evenly spaced in (a, b) (i.e., their locations
were predetermined). In Gaussian quadrature the nodes and weights are chosen so
that Eq. (6.16) yields the exact integral if f (x) is a polynomial of degree 2n + 1 or less;
that is,
4 b
n
w(x)Pm (x)dx = A i Pm (xi ), m ≤ 2n + 1 (6.17)
a i=0
One way of determining the weights and abscissas is to substitute P0 (x) = 1, P1 (x) =
x, . . . , P2n+1 (x) = x 2n+1 in Eq. (6.17) and solve the resulting 2n + 2 equations
4 b
n
j
w(x)x j dx = A i xi , j = 0, 1, . . . , 2n + 1
a i=0
A0 + A1 = 1
A 0 x0 + A 1 x1 = 1
A 0 x02 + A 1 x12 = 2
A 0 x03 + A 1 x13 = 6
The solution is
√
√ 2+1
x0 = 2 − 2 A0 = √
2 2
√
√ 2−1
x1 = 2 + 2 A1 = √
2 2
so that the integration formula becomes
4 ∞
1 √ 1 √ 2 √ 1 √ 2
e−x f (x)dx ≈ √ ( 2 + 1) f 2 − 2 + ( 2 − 1) f 2 + 2
0 2 2
Because of the nonlinearity of the equations, this approach does not work well
for large n. Practical methods of finding xi and A i require some knowledge of orthog-
onal polynomials and their relationship to Gaussian quadrature. There are, however,
several “classical” Gaussian integration formulas for which the abscissas and weights
have been computed with great precision and then tabulated. These formulas can be
used without knowing the theory behind them, because all one needs for Gaussian
integration are the values of xi and A i . If you do not intend to venture outside the
classical formulas, you can skip the next two topics.
*Orthogonal Polynomials
Orthogonal polynomials are employed in many areas of mathematics and numerical
analysis. They have been studied thoroughly, and many of their properties are known.
What follows is a very small compendium of a large topic.
218 Numerical Integration
The set is determined, except for a constant factor, by the choice of the weighting
function and the limits of integration. That is, each set of orthogonal polynomials
is associated with certain w(x), a, and b. The constant factor is specified by stan-
dardization. Some of the classical orthogonal polynomials, named after well-known
mathematicians, are listed in Table 6.1. The last column in the table shows the stan-
dardization used.
3b 2
Name Symbol a b w(x) a w(x) ϕn (x) dx
Legendre pn (x) −1 1 1 2/(2n + 1)
Chebyshev Tn (x) −1 1 (1 − x 2 )−1/2 π/2 (n > 0)
Laguerre L n (x) 0 ∞ e−x 1
√ n
e−x
2
Hermite Hn (x) −∞ ∞ π2 n!
If the first two polynomials of the set are known, the other members of the set can be
computed from Eq. (6.19). The coefficients in the recurrence formula, together with
ϕ 0 (x) and ϕ 1 (x) are given in Table 6.2.
The classical orthogonal polynomials are also obtainable from these formulas
(−1)n d n n
pn (x) = n n
1 − x2
2 n! dx
Tn (x) = cos(n cos−1 x), n > 0
e x d n n −x
L n (x) = x e (6.20)
n! dx n
n
2 d
(e−x )
2
Hn (x) = (−1)n e x
dx n
219 6.4 Gaussian Integration
• It follows from Eq. (6.22) and the orthogonality property in Eq. (6.18) that
4 b
w(x)Pn (x)ϕn+m (x)dx = 0, m ≥ 0 (6.23)
a
where Qn (x), Rn (x), and ϕn+1 (x) are polynomials of the degree indicated by the
subscripts.2 Therefore,
4 b 4 b 4 b
w(x)P2n+1 (x)dx = w(x)Qn (x)dx + w(x)Rn (x)ϕn+1 (x)dx
a a a
But according to Eq. (6.23) the second integral on the right-hand-side vanishes,
so that
4 b 4 b
w(x)P2n+1 (x)dx = w(x)Qn (x)dx (c)
a a
2 It can be shown that Qn (x) and Rn (x) are unique for a given P2n+1 (x) and ϕn+1 (x).
220 Numerical Integration
To arrive at Eq. (a), we must choose for the nodal abscissas xi the roots of
ϕn+1 (x) = 0. According to Eq. (b) we then have
where i (x) are the Lagrange’s cardinal functions spanning the nodes at
x0 , x1 , . . . xn . These functions were defined in Eq. (4.2).
Proof Applying Lagrange’s formula, Eq. (4.1), to Qn (x) yields
n
Qn (x) = Qn (xi ) i (x)
i=0
or
* 4 +
n b
Qn (xi ) A i − w(x) i (x)dx = 0
i=0 a
However the following formulas (given without proof) are easier to compute:
2
Gauss-Legendre A i = 2
(1 − xi2 ) pn+1 (xi )
1
Gauss-Laguerre A i = 2 (6.25)
xi L n+1 (xi )
√
2n+2 (n + 1)! π
Gauss-Hermite Ai = 2
Hn+1 (xi )
has the form E = K (n)f (2n+2) (c), where a < c < b (the value of c is unknown; only
its bounds are given). The expression for K (n) depends on the particular quadrature
being used. If the derivatives of f (x) can be evaluated, the error formulas are useful
in estimating the error bounds.
Gauss-Legendre Quadrature
4 1
n
f (ξ )dξ ≈ A i f (ξ i ) (6.26)
−1 i=0
3 Abramowitz, M. and Stegun, I.A, Handbook of Mathematical Functions, Dover Publications, 1965;
Stroud, A.H.and Secrest, D., Gaussian Quadrature Formulas, Prentice-Hall, 1966.
4 Several such subroutines are listed in W.H. Press et al, Numerical Recipes in Fortran 90, Cambridge
University Press, 1996.