---
title: Singular, infinite and oscillatory integrals
heading: Integrals that standard rules handle badly, and how to fix them
eyebrow: A13 · Lesson 20 · Singular, infinite and oscillatory integrals
xp: 40
---

::: hook
The rules of lessons 17 to 19 assume a smooth integrand on a finite interval. Engineering integrals often break those assumptions: a field near a sharp edge blows up like $1/\sqrt r$, a step response or a noise spectrum runs out to infinity, and a Fourier integral oscillates forever while shrinking slowly. Each case has a standard repair: change variables to remove the singularity, map or truncate the infinite range with a tail estimate, or integrate oscillations lobe by lobe and accelerate the sum. Applied naively, the same rules give slow or wrong answers.
:::

::: play
- The integral $\int_0^\infty\frac{\sin x}{x}dx = \frac\pi2$ is a sum of lobes, one between each pair of zeros, alternating in sign and shrinking slowly.
- The dots are the partial sums after n lobes; they swing above and below $\frac\pi2$ (dashed) and close in only as $1/n$.
- The second set of dots averages neighboring partial sums, and that average is far closer. Repeating the averaging closes in faster still.
:::

```sim plot
view: graph
x: n = 1..8
y: S = 1.3..1.95
points: 1, 1.851937; 2, 1.418152; 3, 1.674762; 4, 1.492161; 5, 1.633965; 6, 1.518034; 7, 1.616086; 8, 1.531131 | label: partial sums | color: ch1
points: 1.5, 1.635044; 2.5, 1.546457; 3.5, 1.583462; 4.5, 1.563063; 5.5, 1.575999; 6.5, 1.567060; 7.5, 1.573608 | label: averages of neighbors | color: ch3
plot: pi/2 | label: π/2 | dashed | color: ch2
```

::: predict
## The trapezoid rule can't be used on $\int_0^1\frac{dx}{\sqrt x}$ (the integrand is infinite at 0), so you use the midpoint rule. How does its error shrink as you double the number of points?

- [ ] By 4, as for smooth integrands
- [ ] By 16
- [x] By only about 1.4
- [ ] It doesn't shrink

::: reveal
By only about $\sqrt2 = 1.4$: the error goes as $h^{1/2}$. Most of the error comes from the first interval, where the integrand has its spike. The substitution $x = t^2$ turns the integral into $\int_0^12\,dt$, which any rule gets exactly.
:::
:::

::: nameit
## Endpoint singularities

For $\int_0^bx^{-\alpha}g(x)\,dx$ with smooth g and $0 < \alpha < 1$:

- **Substitute** to remove the singularity: $x = t^2$ turns $\frac{dx}{\sqrt x}$ into $2\,dt$.
- **Subtract** it: write $g(x) = g(0) + (g(x) - g(0))$, integrate $g(0)x^{-\alpha}$ exactly, and use a rule on the remainder, which vanishes at 0.
- **Use a weighted rule**: Gauss–Jacobi rules have $x^{-\alpha}$ built into their weights.

## Infinite ranges

- **Truncate** at L and estimate the tail analytically: for $e^{-x^2}$ the tail beyond L is about $\frac{e^{-L^2}}{2L}$; for $\frac{1}{1 + x^2}$ it's $\frac\pi2 - \tan^{-1}L \approx \frac1L$, which needs a huge L.
- **Map** to a finite interval: $x = \frac{t}{1 - t}$ sends [0, 1) to [0, ∞) with $dx = \frac{dt}{(1 - t)^2}$. It works when the transformed integrand stays bounded.
- **Gauss–Laguerre** rules integrate $\int_0^\infty e^{-x}f(x)\,dx$ well when f is smooth and grows slowly.

## Oscillatory integrands

For $\int_0^\infty f(x)\sin\omega x\,dx$ with slowly decaying f, integrate between successive zeros to get an alternating series of lobes, then accelerate the partial sums: averaging neighbors repeatedly (Euler's transform) or Aitken's Δ² (lesson 7). Specialized rules (Filon, Levin) build the oscillation into the weights.
:::

::: example
## Compute $\int_0^1\frac{\cos x}{\sqrt x}dx$ two ways.

::: solution
1. **Substitute $x = t^2$.** With $dx = 2t\,dt$ the integral becomes
   $$2\int_0^1\cos(t^2)\,dt$$
   a smooth integrand that Simpson or Gauss rules handle easily. It equals 1.809048.
2. **Or subtract the singularity.**
   $$\begin{aligned} &\int_0^1\frac{\cos x}{\sqrt x}dx \\ &= \int_0^1\frac{dx}{\sqrt x} + \int_0^1\frac{\cos x - 1}{\sqrt x}dx \\ &= 2 + \int_0^1\frac{\cos x - 1}{\sqrt x}dx \end{aligned}$$
3. **The new integrand.** It behaves like $-\frac{x^{3/2}}{2}$ near 0, finite with a finite derivative, and integrates to −0.190952:
   $$2 - 0.190952 = 1.809048$$
   the same value.

**Answer:** both ways give 1.809048.
:::
:::

::: example
## Evaluate $\int_0^\infty\frac{e^{-x}}{1 + x}dx$ with Gauss–Laguerre rules of 2, 3, 4 and 6 points.

::: solution
1. **The rule.** Gauss–Laguerre rules approximate $\int_0^\infty e^{-x}f(x)\,dx$ by $\sum w_if(x_i)$; here $f = \frac{1}{1 + x}$.
2. **Two points.** The nodes are $2 \pm \sqrt2$ and the weights $\frac{2 \pm \sqrt2}{4}$, the larger weight at the smaller node. The rule gives 0.5714.
3. **More points.** The 3-, 4- and 6-point rules give 0.5882, 0.5933 and 0.5958. The true value is 0.596347.
4. **Why it's slow.** f has a pole at x = −1, close to the start of the range, so f is far from a polynomial there.
5. **A better route.** The map $x = \frac{t}{1 - t}$ followed by Gauss–Legendre on [0, 1] reaches all six digits easily.

**Answer:** 0.5714, 0.5882, 0.5933 and 0.5958 with 2, 3, 4 and 6 points, converging slowly toward 0.596347.
:::
:::

::: example
## Accelerate the lobe sums of $\int_0^\infty\frac{\sin x}{x}dx$.

::: solution
1. **The partial sums.** After 1 to 8 lobes they are 1.851937, 1.418152, 1.674762, 1.492161, 1.633965, 1.518034, 1.616086 and 1.531131: still 0.04 from $\frac\pi2 = 1.570796$ after 8 lobes.
2. **Average neighbors.** That gives 1.635, 1.546, 1.583, …, 1.573608.
3. **Average again, twice.** The result is 1.570932 from the same eight lobes, an error of $1.4 \times 10^{-4}$, three hundred times smaller.
4. **What this is.** Repeated averaging is Euler's transform for alternating series; it cancels the slowly decaying swing.

**Answer:** three rounds of averaging turn the eight lobe sums into 1.570932, within $1.4 \times 10^{-4}$ of $\frac\pi2$.
:::
:::

::: check
given: a = 0.25 | 0.6 | 0.75
answer: 1/(1 - a)
tolerance: 0.5%

## What is $\int_0^1x^{-\given{a}}\,dx$?

::: right
Right. $\frac{1}{1 - a}$: finite for any a < 1, though the integrand is infinite at 0.
:::

::: misses
- [1/a] Integrate: $\frac{x^{1-a}}{1 - a}$.
- [any] $\left[\frac{x^{1-a}}{1 - a}\right]_0^1$.
:::
:::

::: check
given: L = 2 | 3 | 4
answer: exp(-L^2)/(2*L)
tolerance: 15%

## About how much does $\int_L^\infty e^{-x^2}dx$ contribute, for L = {L}?

::: right
Right. About $\frac{e^{-L^2}}{2L}$, from integrating by parts.
:::

::: misses
- [exp(-L^2)] Divide by 2L: the integrand falls off in a distance of about $\frac{1}{2L}$.
- [any] $\int_L^\infty e^{-x^2}dx \approx \frac{e^{-L^2}}{2L}$.
:::
:::

::: check
given: L = 10 | 100 | 1000
answer: pi/2 - atan(L)
tolerance: 0.5%

## What tail does truncating $\int_0^\infty\frac{dx}{1 + x^2}$ at L = {L} leave out?

::: right
Right. About $\frac1L$: slowly decaying integrands need a mapping or an analytic tail, not a bigger L.
:::

::: misses
- [1/L^2] The tail of $\frac{1}{x^2}$ is $\frac1L$.
- [any] $\frac\pi2 - \tan^{-1}L$.
:::
:::

::: check
given: n = 2 | 3 | 5
answer: 1/(n - 1)
tolerance: 0.5%

## The substitution $x = \frac{t}{1 - t}$ maps $\int_0^\infty\frac{dx}{(1 + x)^{\given{n}}}$ to an integral over [0, 1]. What is its value?

::: right
Right. The new integrand is $(1 - t)^{n-2}$, a polynomial, and its integral is $\frac{1}{n - 1}$.
:::

::: misses
- [1/n] $\int_0^1(1 - t)^{n-2}dt = \frac{1}{n - 1}$.
- [any] $1 + x = \frac{1}{1 - t}$ and $dx = \frac{dt}{(1 - t)^2}$.
:::
:::

::: check
given: k = 3 | 5 | 10
answer: 2/((k + 0.5)*pi)
tolerance: 1%

## About how large is lobe k = {k} of $\int\frac{\sin x}{x}$, the integral from $k\pi$ to $(k + 1)\pi$?

::: right
Right. The sine lobe has area 2, and $\frac1x$ is about $\frac{1}{(k + 1/2)\pi}$ across it.
:::

::: misses
- [2/(k*pi)] Use the middle of the lobe, $(k + \frac12)\pi$.
- [any] $\frac{2}{(k + \frac12)\pi}$.
:::
:::

::: check
kind: parts
given: p = 0.1 | 0.2 | 0.25 | 0.5 | 0.6 | 0.75

## A rule's error on $\int_0^1x^{-\given{p}}g(x)\,dx$ goes as $h^{1 - p}$.

::: part
answer: 2^(1 - p)
tolerance: 0.5%

### By what factor does halving h shrink the error?

::: misses
- [4] That's for a smooth integrand.
- [any] $2^{1-p}$.
:::
:::

::: part
answer: 1000^(1/(1 - p))
tolerance: 1%

### By what factor must the number of points grow to cut the error 1000-fold?

::: misses
- [any] Solve $N^{1-p} = 1000$.
:::
:::
:::

::: check
kind: choice

## Gauss–Legendre quadrature converges slowly on $\int_0^1\sqrt x\,dx$. Why?

- [ ] Because $\sqrt x$ is not defined for negative x
- [x] Because $\sqrt x$ has an infinite derivative at 0, so no polynomial fits it well there
- [ ] Because the nodes are not equally spaced
- [ ] Because the weights are negative

::: right
Right. Gauss rules are excellent when the integrand is close to a polynomial; a singular derivative spoils that, and the substitution $x = t^2$ fixes it.
:::

::: misses
- [1] The rule only samples inside [0, 1].
- [3] Unequal spacing is what makes Gauss rules powerful.
- [4] Gauss–Legendre weights are all positive.
:::
:::

::: check
kind: derivation
vars: b = 0.5..4, t = 0..2

## Substitute $x = t^2$ in $\int_0^b\frac{\cos x}{\sqrt x}dx$.

::: step
answer: sqrt(b)

### What is the new upper limit?
:::

::: step
answer: 2*cos(t^2)

### What is the new integrand in t?
:::

::: right
Right. $\frac{\cos t^2}{t}\cdot 2t\,dt$: the singularity cancels exactly.
:::
:::

::: explain
## Why does averaging neighboring partial sums speed up an alternating series?

::: model
For a slowly converging alternating series, the partial sums overshoot and undershoot the limit by nearly equal amounts: each new term is almost the same size as the last, with the opposite sign. So the limit lies close to the midpoint of two neighboring partial sums, and averaging them cancels most of the swing, leaving an error set by how fast the terms change size. The averages themselves still alternate around the limit, only more weakly, so averaging again cancels the next layer. Each round removes another order of the slowly decaying error, which is Euler's transformation.
:::
:::

::: practice

::: check
given: a = 0.1 | 0.25 | 0.5 | 0.75 | 0.9 | 0.95
answer: 1/(1 - a)
tolerance: 0.5%

## $\int_0^1x^{-\given{a}}\,dx$?

::: misses
- [any] $\frac{1}{1 - a}$.
:::
:::

::: check
given: L = 10 | 20 | 50 | 100 | 500 | 1000
answer: pi/2 - atan(L)
tolerance: 0.5%

## Tail of $\int\frac{dx}{1 + x^2}$ beyond {L}?

::: misses
- [any] About $\frac1L$.
:::
:::

::: check
given: k = 2..30 int
answer: 2/((k + 0.5)*pi)
tolerance: 1%

## Size of lobe {k} of $\frac{\sin x}{x}$?

::: misses
- [any] $\frac{2}{(k + \frac12)\pi}$.
:::
:::
:::
