Source code for mmf.math.integrate.integrate_1d.clenshaw_curtis

r"""
============================
Clenshaw-Curtis integration.
============================

This is a quadrature method for evaluating integrals over `[-1,1]`
using the change of variables :math:`x=\cos\theta`:

.. math::
   \int_{-1}^1 f(x) \d{x} = 
   \int_0^{\pi} f(\cos\theta)\sin \theta\d{\theta}
   = a_0 + \sum_{k=1}^{\infty}\frac{2a_{2k}}{1-(2k)^2} 

where the coefficients :math:`a_k` are the cosine series

.. math::
   f(\cos\theta) &= \frac{a_{0}}{2} + \sum_{k=1}^{\infty}
       a_k\cos(k\theta)\\
   a_k &= \frac{2}{\pi}\int_0^\pi f(\cos\theta)\cos(k\theta)\d{\theta}

which can be computed using the Fast Fourier Transform (fft).

.. note: This module is not implemented.

"""
__all__ = []

from numpy import pi
import numpy as np
import scipy as sp

[docs]def clenshaw_curtis(f,n): """Return the integral of :math:`\int_{-1}^{1}f(x)\d{x}`. Parameters ---------- f : function n : int Number of quadrature points is `n+1`. """ ''' x = np.cos(np.linspace(0,pi,n+1)) f_x = f(x)/(2*n) g = real(sp.fft(f_x([0:n+1 n:-1:2]))) a = [g[0], g[1:n] +g[2*n:-1:n+2]; g(n+1)]; % Chebyshev coefficients w=0*a';w(1:2:end)=2./(1-(0:2:n).^2); %weightvector I=w*a; %thein '''