archimedes.quadrature.trapezoidalΒΆ

archimedes.quadrature.trapezoidal(
n: int,
periodic: bool = False,
) → QuadratureRuleΒΆ

Equally-spaced trapezoidal quadrature rule.

With periodic=False (default), the usual composite trapezoidal rule: \(n\) nodes \(t_j = -1 + 2j/(n-1)\), \(j = 0, \ldots, n-1\), spanning the closed reference interval \([-1, 1]\), with half-weight at the two endpoints.

With periodic=True, nodes \(t_j = -1 + 2j/n\), equally spaced over the half-open period \([-1, 1)\), with a node only at \(-1\): the domain is periodic, so \(-1\) and \(+1\) denote the same point and including both would double-count it. All weights equal \(2/n\). This form is exact for \(\cos(k \pi t)\) and \(\sin(k \pi t)\) for every \(1 \leq k \leq n - 1\): for equally-spaced points over one period, \(\sum_j e^{i k \cdot 2\pi j/n} = n\) if \(k \equiv 0 \pmod n\), else \(0\), so any nonzero mode strictly below the Nyquist mode \(n\) integrates to exactly zero.

Parameters:
  • n (int) – Number of quadrature nodes. Must be \(\geq 2\) if periodic is False (at least one interval to span), or \(\geq 1\) if periodic is True.

  • periodic (bool, optional) – If True, build the periodic form described above – the natural rule for a Fourier/trigonometric integrand – instead of the plain closed-interval form. Default False.

Returns:

rule – Trapezoidal rule with n nodes, exact for degree-1 polynomials (periodic=False) or for trigonometric polynomials of mode \(\leq n - 1\) (periodic=True).

Return type:

QuadratureRule

Raises:

ValueError – If n is smaller than the minimum for the chosen periodic setting.

Notes

Tiling this rule with composite_quad() is meaningful only for periodic=False: its shared endpoint nodes double up across elements exactly like gauss_lobatto()’s. The periodic form’s nodes already span the whole reference domain by construction, so tiling it is mechanically possible (the shared measure is uniform-weight) but not the intended use.