core.Lagrange module

class LagrangeApproximation(points, fValues=None)[source]

Bases: object

Class approximating any function on a given set of points using barycentric Lagrange interpolation.

Let note \((t_j)_{0\leq j<n}\) the set of points, then any scalar function \(f\) can be approximated by the barycentric formula :

\[p(x) = \frac{\displaystyle \sum_{j=0}^{n-1}\frac{w_j}{x-x_j}f_j} {\displaystyle \sum_{j=0}^{n-1}\frac{w_j}{x-x_j}},\]

where \(f_j=f(t_j)\) and

\[w_j = \frac{1}{\prod_{k\neq j}(x_j-x_k)}\]

are the barycentric weights. The theory and implementation is inspired from this paper.

Parameters:

points (list, tuple or np.1darray) – The given interpolation points, no specific scaling, but must be ordered in increasing order.

points

The interpolating points

Type:

np.1darray

weights

The associated barycentric weights

Type:

np.1darray

getIntegrationMatrix(intervals, numQuad='LEGENDRE_NUMPY')[source]

Compute the integration matrix for a given set of intervals.

For instance, if we note \(\vec{f}\) the vector containing the \(f_j=f(t_j)\) values, and \((\tau_{m,left}, \tau_{m,right})_{0\leq m<M}\) the different interval where the function should be integrated using the barycentric interpolant polynomial. Then \(\Delta[\vec{f}]\), the vector containing the approximations of

\[\int_{\tau_{m,left}}^{\tau_{m,right}} f(t)dt,\]

can be obtained using :

\[\Delta[\vec{f}] = P_{Integ} \vec{f},\]

where \(P_{Integ}\) is the interpolation matrix returned by this method.

Parameters:
  • intervals (list of pairs) – A list of all integration intervals.

  • numQuad (str, optional) –

    Quadrature rule used to integrate the interpolant barycentric polynomial. Can be :

    • ’LEGENDRE_NUMPY’ : Gauss-Legendre rule from Numpy

    • ’LEGENDRE_SCIPY’ : Gauss-Legendre rule from Scipy

    • ’FEJER’ : internaly implemented Fejer-I rule

    The default is ‘LEGENDRE_NUMPY’.

Returns:

PInter – The integration matrix, with \(M\) rows (number of intervals) and \(n\) columns.

Return type:

np.2darray(M, n)

getInterpolationMatrix(times)[source]

Compute the interpolation matrix for a given set of discrete “time” points.

For instance, if we note \(\vec{f}\) the vector containing the \(f_j=f(t_j)\) values, and \((\tau_m)_{0\leq m<M}\) the “time” points where to interpolate. Then \(I[\vec{f}]\), the vector containing the interpolated \(f(\tau_m)\) values, can be obtained using :

\[I[\vec{f}] = P_{Inter} \vec{f},\]

where \(P_{Inter}\) is the interpolation matrix returned by this method.

Parameters:

times (list-like or np.1darray) – The discrete “time” points where to interpolate the function.

Returns:

PInter – The interpolation matrix, with \(M\) rows (size of the times parameter) and \(n\) columns.

Return type:

np.2darray(M, n)

property n
computeFejerRule(n)[source]

Compute a Fejer rule of the first kind, using DFT (Waldvogel 2006) Inspired from quadpy (https://github.com/nschloe/quadpy @Nico_Schlömer)

Parameters:

n (int) – Number of points for the quadrature rule.

Returns:

  • nodes (np.1darray(n)) – The nodes of the quadrature rule

  • weights (np.1darray(n)) – The weights of the quadrature rule.