Gauss Quadrature Method for Numerical Integration
by admin in Math, Statistics, and Optimization , MATLAB Family , Numerical Integration on April 30, 2019Choose Your Desired Option(s)
×This code calculates the Numerical Integration of a given equation on a predefined interval using Gauss Quadrature Method. This codes uses variable step size and gives accurate and fast results.
Code Outputs:
 Chart of Integration History
 Chart of Residuals
 Printed values of Final Iteration value, Accuracy and Number of Iterations.
Result is: 0.86271, Accuracy: 0.00026456, NO Iterations: 7
Input Requirements:
 The equation you intended to integrate
 Integration interval [a b].
 predefined error (default 0.001).
 Maximum number of iterations (default 1000).
About The Method (Gaussian quadrature):
In numerical analysis, a quadrature rule is an approximation of the definite integral of a function, usually stated as a weighted sum of function values at specified points within the domain of integration. (See numerical integration for more on quadrature rules.) An npoint Gaussian quadrature rule, named after Carl Friedrich Gauss, is a quadrature rule constructed to yield an exact result for polynomials of degree 2n − 1 or less by a suitable choice of the nodes x_{i} and weights w_{i} for i = 1, …, n. The most common domain of integration for such a rule is taken as [−1,1], so the rule is stated as
which is exact for polynomials of degree 2n1 or less. This exact rule is known as the GaussLegendre quadrature rule. The quadrature rule will only be an accurate approximation to the integral above if f(x) is wellapproximated by a polynomial of degree 2n1 or less on [1,1].
The GaussLegendre quadrature rule is not typically used for integrable functions with endpoint singularities. Instead, if the integrand can be written as
where g(x) is wellapproximated by a lowdegree polynomial, then alternative nodes x’i and weights w’i will usually give more accurate quadrature rules. These are known as GaussJacobi quadrature rules, i.e.,
Common weights include 1/sqrt(1x^2) (Chebyshev–Gauss) and sqrt(1x^2). One may also want to integrate over semiinfinite (GaussLaguerre quadrature) and infinite intervals (Gauss–Hermite quadrature).
It can be shown (see Press, et al., or Stoer and Bulirsch) that the quadrature nodes x_{i} are the roots of a polynomial belonging to a class of orthogonal polynomials (the class orthogonal with respect to a weighted innerproduct). This is a key observation for computing Gauss quadrature nodes and weights.
Fundamental Theorem:
Let p_{n} be a nontrivial polynomial of degree n such that
If we pick the n nodes x_{i} to be the zeros of p_{n}, then there exist n weights w_{i} which make the Gaussquadrature computed integral exact for all polynomials h(x) of degree 2n − 1 or less. Furthermore, all these nodes x_{i} will lie in the open interval (a, b) (Stoer & Bulirsch 2002, pp. 172–175).
The polynomial p_{n} is said to be an orthogonal polynomial of degree n associated to the weight function ω(x). It is unique up to a constant normalization factor. The idea underlying the proof is that, because of its sufficiently low degree, h(x) can be divided by Pn(x) to produce a quotient q(x) of degree strictly lower than n, and a remainder r(x)of still lower degree, so that both will be orthogonal to Pn(x), by the defining property of Pn(x). Thus
Because of the choice of nodes x_{i}, the corresponding relation
holds also. The exactness of the computed integral for h(x) then follows from corresponding exactness for polynomials of degree only n or less (as is r(x)).
General formula for the weights:
The weights can be expressed as
where ak is the coefficient of x^k in Pk(x). To prove this, note that using Lagrange interpolation one can express r(x) in terms of r(xi) as
because r(x) has degree less than n and is thus fixed by the values it attains at n different points. Multiplying both sides by ω(x) and integrating from a to b yields
The weights ω_{i} are thus given by
This integral expression for ωi can be expressed in terms of the orthogonal polynomials Pn(x) and Pn1(x) as follows.
We can write
where an is the coefficient of x^n in Pn(x). Taking the limit of x to xi yields using L’Hôpital’s rule
We can thus write the integral expression for the weights as:
In the integrand, writing
yields
provided k <= n, because
is a polynomial of degree k1 which is then orthogonal to Pn(x). So, if q(x) is a polynomial of at most nth degree we have
We can evaluate the integral on the right hand side for
as follows. Because Pn(x)/(xxi) is a polynomial of degree n1, we have
where s(x) is a polynomial of degree n2. Since s(x) is orthogonal to Pn1(x) we have
We can then write
The term in the brackets is a polynomial of degree n2, which is therefore orthogonal to Pn1(x). The integral can thus be written as
According to equation (2 wi), the weights are obtained by dividing this by P’n1(xi) and that yields the expression in equation (1 wi). wi can also be expressed in terms of the orthogonal polynomials Pn(x) and now Pn+1(x). In the 3term recurrence relation Pn+1(xi) = (a) Pn(xi) + (b) Pn1(xi) the term with Pn(xi) vanishes, so Pn1(xi) in Eq. (1) can be replaced by Pn+1(x)/b.
Proof that the weights are positive:
Consider the following polynomial of degree 2n2
where, as above, the x_{j} are the roots of the polynomial Pn(x). Clearly f(xj) = deltaij. Since the degree of f(x) is less than 2n1, the Gaussian quadrature formula involving the weights and nodes obtained from Pn(x) applies. Since f(xi) = 0 for j not equal to i, we have
Since both w(x) and f(x) are nonnegative functions, it follows that wi > 0.
Computation of Gaussian quadrature rules:
There are many algorithms for computing the nodes x_{i} and weights w_{i} of Gaussian quadrature rules. The most popular are the GolubWelsch algorithm requiring O(n^{2}) operations, Newton’s method for solving Pn(x) = 0 using the threeterm recurrence for evaluation requiring O(n^{2}) operations, and asymptotic formulas for large n requiring O(n) operations.
Recurrence Relation:
Orthogonal polynomials Pr with (Pr, Ps) = 0 for r =/= s for a scalar product Pr = r and leading coefficient one (i.e. monic orthogonal polynomials) satisfy the recurrence relation
and scalar product defined
for r = 0,1,…,n1 where n is the maximal degree which can be taken to be infinity, and where
First of all, the polynomials defined by the recurrence relation starting with P0(x) = 1 have leading coefficient one and correct degree. Given the starting point by P0, the orthogonality of Pr can be shown by induction. For r = s = 0 one has
Now if P0,P1,…,Pr are orthogonal, then also Pr+1, because in
all scalar products vanish except for the first one and the one where Ps meets the same orthogonal polynomial. Therefore,
However, if the scalar product satisfies (xf,g) = (f,xg) (which is the case for Gaussian quadrature), the recurrence relation reduces to a threeterm recurrence relation: For s < r1, xps is a polynomial of degree less than or equal to r − 1. On the other hand, is orthogonal to every polynomial of degree less than or equal to r − 1. Therefore, one has (xpr,ps) = (pr,xps) = 0 and ar,s = 0 for s < r − 1. The recurrence relation then simplifies to
or
(with the convention P1(x) = 0 ) where
(the last because of
since xPr1 differs from Pr by a degree less than r).
The GolubWelsch Algorithm:
The threeterm recurrence relation can be written in matrix form
where
en is the nth standard basis vector, i.e., en = [0,…,0,1]^T , and J is the socalled Jacobi matrix:
The zeros xj of the polynomials up to degree n, which are used as nodes for the Gaussian quadrature can be found by computing the eigenvalues of this tridiagonal matrix. This procedure is known as Golub–Welsch algorithm.
For computing the weights and nodes, it is preferable to consider the symmetric tridiagonal matrix big J with elements
J and big J are similar matrices and therefore have the same eigenvalues (the nodes). The weights can be computed from the corresponding eigenvectors: If phi^(j) is a normalized eigenvector (i.e., an eigenvector with euclidean norm equal to one) associated to the eigenvalue x_{j}, the corresponding weight can be computed from the first component of this eigenvector, namely:
where is the integral of the weight function
See, for instance, (Gil, Segura & Temme 2007) for further details.
Error Estimates:
The error of a Gaussian quadrature rule can be stated as follows (Stoer & Bulirsch 2002, Thm 3.6.24). For an integrand which has 2n continuous derivatives,
for some ξ in (a, b), where p_{n} is the monic (i.e. the leading coefficient is 1) orthogonal polynomial of degree n and where
In the important special case of ω(x) = 1, we have the error estimate (Kahaner, Moler & Nash 1989, §5.2)
Stoer and Bulirsch remark that this error estimate is inconvenient in practice, since it may be difficult to estimate the order 2n derivative, and furthermore the actual error may be much less than a bound established by the derivative. Another approach is to use two Gaussian quadrature rules of different orders, and to estimate the error as the difference between the two results. For this purpose, Gauss–Kronrod quadrature rules can be useful.
References:
[1] Implementing an Accurate Generalized Gaussian Quadrature Solution to Find the Elastic Field in a Homogeneous Anisotropic Media
[2] Abramowitz, Milton; Stegun, Irene Ann, eds. (1983) [June 1964]. ‘Chapter 25.4, Integration’. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. Applied Mathematics Series. 55 (Ninth reprint with additional corrections of tenth original printing with corrections (December 1972); first ed.). Washington D.C.; New York: United States Department of Commerce, National Bureau of Standards; Dover Publications. ISBN 9780486612720. LCCN 6460036. MR 0167642. LCCN 6512253.
[3] Anderson, Donald G. (1965). ‘Gaussian quadrature formulae for ‘. Math. Comp. 19 (91): 477–481. doi:10.1090/s00255718196501785691.
[4] Golub, Gene H.; Welsch, John H. (1969), ‘Calculation of Gauss Quadrature Rules’, Mathematics of Computation, 23 (106): 221–230, doi:10.1090/S0025571869996471, JSTOR 2004418
[5] Gautschi, Walter (1968). ‘Construction of Gauss–Christoffel Quadrature Formulas’. Math. Comp. 22 (102). pp. 251–270. doi:10.1090/S00255718196802281710. MR 0228171.
[6] Gautschi, Walter (1970). ‘On the construction of Gaussian quadrature rules from modified moments’. Math. Comp. 24. pp. 245–260. doi:10.1090/S00255718197002851176. MR 0285177.
[7] Piessens, R. (1971). ‘Gaussian quadrature formulas for the numerical integration of Bromwich’s integral and the inversion of the laplace transform’. J. Eng. Math. 5 (1). pp. 1–9. Bibcode:1971JEnMa…5….1P. doi:10.1007/BF01535429.
[8] Danloy, Bernard (1973). ‘Numerical construction of Gaussian quadrature formulas for and ‘. Math. Comp. 27 (124). pp. 861–869. doi:10.1090/S0025571819730331730X. MR 0331730.
Download Details
$4.99
Release Information

Price:
$4.99

Released:
April 30, 2019

Last Updated:
May 28, 2019
Subscribe
Most of the time, we share our discount coupons to our Newsletter Subscribers only. And get products updates also!
Recent Blog Posts
Development of Russian Cars Plat...
389 Views
Reinforcement Learning with MATLAB
286 Views
MATLAB Code For Face Detection
401 Views
LSB Based Image Steganography Us...
530 Views
RGB Image to Grayscale Image Con...
342 Views