Numerical Integration & Differentiation

handling singular integrals

Standard quadrature rules quietly assume the integrand is a smooth, bounded function on a finite interval. Real integrals often violate this: the integrand may blow up at an endpoint (like 1/sqrt(x) at 0), have an infinitely steep slope, or the range itself may stretch to infinity (like an integral from 0 to infinity). Plugging such integrals into an ordinary rule gives slow, inaccurate, or outright nonsensical answers. Handling singular integrals is the toolkit of tricks that tame them.

Several strategies, often combined. First, a CHANGE OF VARIABLE can absorb the singularity: substituting x = t^2 turns the integral of 1/sqrt(x) into a smooth integrand in t, and the celebrated tanh-sinh (double exponential) transformation maps a finite interval so that endpoint singularities are crushed flat, letting a simple rule converge astonishingly fast. Second, SUBTRACTION: if you know the singular part analytically, integrate it by hand and apply quadrature only to the smooth remainder. Third, SPECIAL RULES: Gauss-Jacobi quadrature builds the endpoint singularity x^a (1-x)^b directly into the weight function so the nodes and weights handle it exactly, and Gauss-Laguerre / Gauss-Hermite handle the weights e^(-x) and e^(-x^2) on infinite ranges. For an infinite range you can also substitute, say x = t/(1 - t), to fold infinity back onto a finite interval.

Knowing how to handle singularities is the difference between a quadrature routine that returns a trustworthy number and one that returns garbage or never converges. The honest distinction to keep straight: an INTEGRABLE singularity (the integral is finite even though the integrand is unbounded, like 1/sqrt(x) near 0) can be handled by these methods; a NON-integrable one (the integral genuinely diverges) cannot be rescued by any quadrature — no amount of cleverness integrates infinity. And feeding a singular integrand to a naive adaptive routine without telling it about the singularity often triggers endless subdivision near the bad point, burning evaluations while barely converging.

Integrate 1/sqrt(x) on [0, 1] (true 2). A plain trapezoidal rule fails because f is infinite at 0. Substitute x = t^2, dx = 2t dt: the integral becomes the integral of (1/t)(2t dt) = 2 dt from 0 to 1, a perfectly smooth constant integrand giving 2 exactly. The singularity has been transformed away.

A change of variable can absorb an endpoint singularity entirely.

Distinguish integrable from non-integrable singularities: quadrature tricks rescue a finite integral with an unbounded integrand, but nothing makes a genuinely divergent integral converge. And never hand a singular integrand to a naive adaptive routine blind — it will subdivide forever near the singularity unless you transform it or use a singularity-aware rule.

Also called
integrable singularitiesinfinite-range integralsweakly singular integrals奇異積分處理無窮區間積分