From first principles
Choose quadrature nodes by matching moments
A quadrature formula can be designed by asking it to reproduce integrals of successive monomials. On \([-1,1]\), take two nodes at \(\pm a\) with equal weight \(w\), exploiting reflection symmetry of the interval and uniform measure. This model integrates every odd polynomial exactly because its two sampled values cancel. Exactness for the constant and quadratic terms requires
The equations give \(w=1\) and \(a=1/\sqrt3\). By linearity the resulting two-point Gauss rule is exact for every cubic polynomial,
Its nodes lie inside the interval, making it useful when endpoints are expensive or shared information is unavailable. Higher-degree accuracy for an arbitrary function depends on the size of the unresolved part of its shape. Mapping another interval affinely requires scaling both the nodes and the weights by the appropriate coordinate transformation.
Background · Quadrature degree
Exactness through degree d is an algebraic property. For a nonsmooth or poorly sampled integrand the observed rate can be much lower.
Derivation and applications
Derive a two-point rule when one endpoint must be sampled
Suppose a measurement at one endpoint is already required for another purpose. How much polynomial exactness remains if the second sample can be placed freely? On \([0,1]\), fix the first node at zero and place the second at \(a\). Denote their weights \(w_0,w_1\). Exact integration of the first three monomials requires
Dividing the quadratic condition by the linear one determines \(a=2/3\); back-substitution fixes both weights. This is the two-node left Gauss–Radau rule. Its first missed monomial can be computed directly,
To see what determines the sign of the error for a more general function, interpolate with a quadratic that matches \(f\) at zero and matches both \(f\) and its derivative at the interior node. The quadrature sees the same values as that quadratic, which it integrates exactly. For a function with continuous third derivative the interpolation remainder has a factor \(x(x-2/3)^2\), nonnegative over the interval. Integrating and applying the weighted mean value theorem gives
A convexity assumption alone does not determine the sign here, since the error depends on the third derivative. Scaling the panel length by \(h\) multiplies the third-derivative error coefficient by \(h^4\).
Worked example
Integrate a profile on a physical interval
On \(0\le t\le3\) let a flow rate be \(q(t)=2+t^2\) in consistent units. The Radau nodes are \(0\) and \(2\), and the integral is
Direct integration gives \(6+9=15\). The freely chosen interior station resolves quadratic curvature using only one new measurement.
Second application
Bound the error for a rising exponential
On \([0,1]\) the rule gives \(Q(e^x)=0.25+0.75e^{2/3}=1.71080\), compared with \(e-1=1.71828\). Its error \(0.00748\) is positive. Since \(1\le f'''\le e\), the derived bound brackets the error between \(1/216=0.00463\) and \(e/216=0.0126\), consistent with the direct result.
Three nodes sampling a Gaussian ensemble
An ensemble has normalised density \(p(x)=e^{-x^2}/\sqrt{\pi}\) over the real line. An instrument records the mean of \(\cos(\omega x)\). Its effective response changes from a slowly varying function to a rapidly oscillating one as \(\omega\) increases. Build a quadrature rule that samples the ensemble only three times. The aim is to learn what exactness for polynomials implies for an observable with a variable frequency.
Exploit symmetry and put nodes at \(-c,0,c\), with equal outer weights \(w\) and central weight \(1-2w\). Odd moments vanish automatically. Integration by parts using \(p'(x)=-2xp(x)\) gives ensemble second and fourth moments \(1/2\) and \(3/4\). Matching them imposes \(2wc^2=1/2\) and \(2wc^4=3/4\). Divide the equations to find \(c^2=3/2\). Substitution gives \(w=1/6\), hence central weight \(2/3\). This proves exactness through degree five without needing a table of Gauss–Hermite nodes.
For the instrument response the three readings give
For comparison derive the exact transform \(I(\omega)=\int p(x)\cos(\omega x)\,dx\). Differentiating under the integral and once integrating by parts using the derivative of the Gaussian gives
with \(I(0)=1\). Hence \(I=\exp(-\omega^2/4)\). This independent answer tests the numerical method in the transition from well-resolved response to nearly complete cancellation.
Open full-size diagramExpand the cosine in even powers near zero. Its constant, quadratic and quartic terms are integrated exactly. The first possible error has order \(\omega^6\); the sixth ensemble moment is \(15/8\), while the rule produces \(9/8\). The difference begins as \(Q-I=\omega^6/960+O(\omega^8)\). This is a local frequency statement. At high frequency the exact response tends to zero, but the discrete sum repeatedly returns to one. Increasing the node count extends the useful frequency range, as the notebook's independent 64-node comparison illustrates.
A sensor that records only these three phase samples cannot distinguish a large carrier with phases differing by integer multiples of a full cycle from zero carrier at the sampling nodes. This is a property of the information supplied to the quadrature, not a failure of the root-finding procedure that produced the nodes. A useful extra observation would be at a coordinate whose phase differs for the two suspected frequencies; merely repeating a measurement at the central node cannot resolve them.
The Gaussian weight in this example has variance one half. If a laboratory reports a Gaussian standard deviation \(\sigma\) in physical units, first set the physical coordinate to \(\sqrt{2}\sigma x\). The carrier in the dimensionless quadrature then becomes \(\sqrt{2}\sigma\omega_{\rm physical}\). Scaling the nodes without scaling the frequency in the reference calculation would compare two different instruments.
Find a nonzero frequency at which all three individual measurements return exactly one and calculate the true ensemble mean there.
Work through the solution
Choose \(\omega=2\pi/c\). Then \(\omega c=2\pi\), so both outer cosines and the central cosine equal one. The true mean is
The error here is large despite exactness for five polynomial degrees; the integrand's scale has changed relative to the chosen sampling nodes.
Change parameters · Explore this notebook example
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Spend samples where they are most useful
When the integrand is a callable function, quadrature nodes need not coincide with pre-existing sensors. A rule with \(n\) distinct nodes and \(n\) weights has \(2n\) scalar parameters. Can these integrate every polynomial through degree \(2n-1\)? Merely counting parameters does not prove existence. The Gauss construction supplies nodes for a positive weight function on an interval and establishes the exactness by orthogonality.
Start on \([-1,1]\) with a symmetric two-node rule of the form \(w[f(-c)+f(c)]\). Testing the constant function gives \(2w=2\), hence \(w=1\). Symmetry automatically integrates the odd monomials \(x,x^3\). Testing \(x^2\) gives \(2c^2=2/3\), or \(c=1/\sqrt3\). These four independent moment conditions establish exactness on every cubic by linearity. Testing \(x^4\) produces \(2/9\), whereas its integral is \(2/5\). The error appears at degree four exactly as the parameter count suggested.
Prove the general degree claim
Let \(P_n\) be the degree-\(n\) orthogonal polynomial for the prescribed positive integration weight \(w(x)\). Use its \(n\) distinct interior zeros as nodes. Define the weights by integrating the Lagrange basis on these nodes, so every polynomial of degree at most \(n-1\) is already integrated exactly. To treat any polynomial \(f\) of degree at most \(2n-1\), divide it by \(P_n\), giving \(f=P_n q+r\) with \(\deg q,\deg r\leq n-1\).
The integral of \(P_nq\) vanishes by orthogonality, and every quadrature evaluation of that product vanishes because the nodes are zeros of \(P_n\). Both the integral and the rule therefore reduce to the same value for \(r\). This proves exactness. There is a sharp obstruction to one extra degree: \(P_n^2\) is nonnegative, positive except at finitely many points, and all its sampled values vanish. Its positive integral cannot be reproduced by this rule. Positivity of the individual Gauss weights follows by applying exactness to the square of each Lagrange basis polynomial.
Transfer the rule into a physical element
An element \([a,b]\) is obtained by the affine change \(x=m+\ell \xi\), with midpoint \(m=(a+b)/2\), half-length \(\ell=(b-a)/2\), and \(dx=\ell\,d\xi\). Both the node locations and their weights change. For \([2,4]\), the two physical nodes are \(3\pm1/\sqrt3\), with unit physical weights. The integral of \(x^3\) is
Summing the nodal cubes gives
A missing Jacobian would escape detection on this particular element where \(\ell=1\); test a second element of a different length.
In a linear finite element with constant density, each consistent mass entry integrates a product of two linear basis functions, hence a quadratic. Two Gauss points integrate it exactly. On a unit element the true mass matrix has diagonal \(1/3\) and off-diagonal \(1/6\). Using just the midpoint makes all four entries \(1/4\). The alternating nodal vector \((1,-1)^T\) then has zero discrete mass although its interpolated field has a positive squared integral. This loss of a mode is a practical consequence of insufficient quadrature. With curved mappings or varying coefficients, determine the degree and smoothness of the entire transformed integrand before reusing a quadrature order.
Distinguish a load integral from a stiffness integral
On the same unit element, a constant axial stiffness integrand made from two derivatives of linear shape functions is itself constant. A single midpoint therefore reproduces the stiffness exactly, despite failing for the consistent mass. If \(EA(x)=1+x^2\), the same midpoint now approximates its integral by 1.25, whereas the exact result is \(4/3\). The difference is \(1/12\) in the chosen units. A rule sufficient for one element contribution may thus be insufficient for another in the same analysis.
To select a quadrature order systematically, multiply out the shape functions or their derivatives, coefficient field and mapping Jacobian in the reference coordinate. For discontinuous coefficients, a single smooth polynomial degree may not exist on the entire element. Splitting at the interface, or integrating separate material subcells, then addresses the modelling geometry more directly than increasing the polynomial exactness of one unbroken-panel rule.
Retain both endpoints and derive the best three-point rule
Some instruments already provide readings at the ends of every panel, or adjacent elements need to communicate values at a shared boundary. If endpoints must be quadrature nodes, the unrestricted Gaussian degree \(2n-1\) is generally unavailable. To see the obstruction on \([-1,1]\) with \(n\) nodes including both ends, form the polynomial \((1-x^2)\prod_{\rm interior}(x-x_j)^2\). It vanishes at every evaluation point and is nonnegative throughout the interval. Its true integral is positive but every quadrature rule using just these values returns zero. Its degree is \(2n-2\), so exactness can extend at most through \(2n-3\).
For three symmetric nodes the interior point is zero. Symmetry forces equal endpoint weights \(a\), with central weight \(b\). Reproducing the constants and the square gives \(2a+b=2\) and \(2a=2/3\), so
Odd powers integrate to zero by symmetry, hence the rule is exact through degree three, attaining its constrained upper bound. Under affine mapping this is the three-node Gauss–Lobatto rule, also known as the single-panel Simpson rule. Its weights and node placement now follow directly from a measurement constraint and a moment calculation.
Contrast endpoint inclusion with free node placement
Consider the local mass entry on one dimensionless interval \([-1,1]\) for a quadratic middle-node shape function \(\phi(x)=1-x^2\) and uniform density. Its exact consistent mass contribution is
The endpoint-constrained three-node rule sees values \(0,1,0\), giving \(4/3\), an overestimate of \(4/15\), or 25 percent. The discrepancy arises solely from the quartic term. For a quadratic field, reproducing the field at all interpolation nodes does not imply correct integration of its square.
A three-point Gauss rule has free nodes at zero and \(\pm\sqrt{3/5}\), with weights \(8/9,5/9,5/9\). The outer samples have \(\phi^2=(1-3/5)^2=4/25\). Their total contribution is \(2(5/9)(4/25)=8/45\); adding \(8/9\) recovers \(16/15\). In a nodal element the endpoint-constrained rule makes off-diagonal mass entries vanish when basis functions are evaluated only at their own interpolation nodes. This diagonal mass approximation facilitates explicit updates even while changing the exact form.
Selecting either rule is therefore a physical and numerical modelling choice. A modal frequency depends on the ratio of stiffness energy to mass energy, so changing one mass entry may shift computed frequencies even if a static patch test passes. If the density varies across the element, include its degree or smoothness in the integrand before claiming exactness from polynomial degree counting. A discontinuity inside a panel defeats this counting argument until the integration interval is split.
As a check on assembly, sum all rows of the mass matrix. The shape functions form a partition of unity, so the total mass of a constant field is the integral of the density. The nodal diagonal rule reproduces this total for uniform density despite the incorrect middle diagonal entry just calculated. Testing the mass of a constant alone would therefore fail to expose the approximation affecting internal motion.
Does a high polynomial degree resolve a narrow peak?
Integrate \(1/(x^2+a^2)\) on \([-1,1]\). The exact answer is \(2\arctan(1/a)/a\). Use the ordinary Legendre nodes without centring a separate subinterval on the peak; vary only its half-width \(a\).

Read values from the plot
| Gauss–Legendre nodes | Peak half-width 0.12 | Peak half-width 0.35 | Peak half-width 0.7 |
|---|---|---|---|
| 1 | 114.7 | 9.2744 | 1.3386 |
| 3 | 39.347 | 1.742 | 0.090369 |
| 5 | 19.029 | 0.41492 | 0.0066724 |
| 8 | 6.0323 | 0.051839 | 0.00013401 |
| 10 | 3.9106 | 0.013187 | 9.8795e−6 |
Change parameters · Does a high polynomial degree resolve a narrow peak?
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.