archimedes.approximation.LagrangeBasis¶
- class archimedes.approximation.LagrangeBasis( )¶
Lagrange (nodal) interpolating polynomial basis
The basis is constructed from Lagrange cardinal polynomials \(\{\ell_0, \ldots, \ell_{n-1}\}\) for a fixed set of nodes.
Evaluated via the first, “true” barycentric formula ([1], [2]):
\[\ell_i(x) = \frac{w_i / (x - x_i)}{\sum_j w_j / (x - x_j)}, \qquad w_i = \frac{1}{\prod_{j \neq i} (x_i - x_j)}\]where \(\ell_i(x_k) = \delta_{ik}\) at \(x = x_k\).
Derivatives of every order are supported and exact: \(\ell_j^{(k)}\) is itself a polynomial of degree \(\leq n - 1\) and so is represented exactly in this same basis,
\[\ell_j^{(k)}(x) = \sum_i D^k_{ij} \, \ell_i(x),\]where \(D_{ij} = \ell_j'(x_i)\) is the classical differentiation matrix.
Typically not constructed directly; instead, one usually works with a
PiecewiseBasisbased on Lagrange elements or the higher-levelFunctionSpaceconstructed fromFunctionSpace.piecewise(kind="lagrange", ...).- Parameters:
reference_nodes (array_like) – Distinct interpolation nodes on the reference domain
[-1, 1].node_family (callable, optional) –
n -> nodes, used internally to pick the node set whenever a differently sized basis of the same kind is needed. Defaults to Gauss-Lobatto.Any
ndistinct nodes span the same \(P_{n-1}\), so the choice affects only conditioning and which degrees of freedom are nodal.
See also
FunctionSpace.piecewiseConvenience constructor for a
FunctionSpacethat supports piecewise Lagrange elements.
References
Methods
boundary_dofs([order])Indices of the degrees of freedom at the left/right ends of the domain.
equispaced(n)Construct a Lagrange basis using evenly spaced nodes.
evaluate(x[, deriv, a, b, side])Evaluate all
n_basisbasis functions atx.Construct a Lagrange basis using Gauss-Legendre nodes.
Construct a Lagrange basis using Gauss-Lobatto nodes
gauss_radau(n[, endpoint])Construct a Lagrange basis using Gauss-Radau nodes.
Attributes
The target-domain parameters this basis expects.
Whether this basis is orthonormal with respect to a probability measure (unit mass) rather than the raw weight of the associated
Measure.Number of independent variables the basis functions take.
node_familyreference_nodes- classmethod equispaced(
- n: int,
Construct a Lagrange basis using evenly spaced nodes.
- Parameters:
n (int) – Number of evenly spaced nodes. Also the number of Lagrange basis functions.
- Returns:
Lagrange basis with evenly spaced nodes.
- Return type:
- classmethod gauss_legendre(
- n: int,
Construct a Lagrange basis using Gauss-Legendre nodes.
- Parameters:
n (int) – Number of Gauss-Legendre quadrature nodes. Also the number of Lagrange basis functions.
- Returns:
Lagrange basis with Gauss-Legendre nodes.
- Return type:
- classmethod gauss_lobatto(
- n: int,
Construct a Lagrange basis using Gauss-Lobatto nodes
- Parameters:
n (int) – Number of Gauss-Lobatto quadrature nodes. Also the number of Lagrange basis functions.
- Returns:
Lagrange basis with Gauss-Lobatto nodes.
- Return type:
- classmethod gauss_radau(
- n: int,
- endpoint: str = 'left',
Construct a Lagrange basis using Gauss-Radau nodes.
- Parameters:
n (int) – Number of Gauss-Radau quadrature nodes. Also the number of Lagrange basis functions.
endpoint (str, default "left") – Which endpoint to fix (“left” or “right”).
- Returns:
Lagrange basis with Gauss-Radau nodes.
- Return type:
- boundary_dofs(order: int = 0) tuple[int | None, int | None]¶
Indices of the degrees of freedom at the left/right ends of the domain.
Can be used for example to set boundary conditions or enforce continuity at the domain endpoints.
- Parameters:
order (int, optional) – Derivative order to look up. Default 0 (the endpoint value).
- Returns:
left, right – Index into this basis’s functions, or
Nonewhere there is no degree of freedom of that order at that end.- Return type:
int or None
Notes
Only meaningful for nodal families (e.g.
LagrangeBasis) with nodes at the endpoints. Modal families (e.g.OrthogonalPolynomialBasis) and nodal bases with interior-only nodes (Gauss-Legendre points, for instance) do not have boundary DOFs.
- evaluate(x, deriv: int = 0, *, a=None, b=None, side: str = RIGHT)¶
Evaluate all
n_basisbasis functions atx.- Parameters:
x (array_like) – Evaluation points, shape
(npts,).deriv (int, optional) – Order of derivative to evaluate. Default 0.
side ({"right", "left"}, optional) – Which one-sided limit to take where the basis is two-valued. Default
"right". Irrelevant for smooth bases.**domain_kwargs – Target-domain parameters; see the subclass docstring.
- Returns:
phi – Basis values (or
deriv-th derivatives), shape(npts, n_basis).- Return type:
ndarray
- property Parameters: type¶
The target-domain parameters this basis expects.
A
Parameterssubclass (e.g.UnitInterval.Parameters). Returns the type, not an instance.Determines which reference domain the basis is defined on, for example:
UnitIntervalfor \([-1, 1]\).HalfLinefor \([0, \infty)\).RealLinefor \((-\infty, \infty)\).
- density: bool = False¶
Whether this basis is orthonormal with respect to a probability measure (unit mass) rather than the raw weight of the associated
Measure.Only meaningful for orthogonal polynomial families based on a
Measure(in particularOrthogonalPolynomialBasis); other families should leave thisFalse.
- property n_basis: int¶
- ndim: int = 1¶
Number of independent variables the basis functions take.
Typically 1, since most bases are univariate.
TensorBasisis the exception, with one variable per tensored factor.