Polynomial Weight Function (polynomial_weight_function)

class pypint.integrators.weight_function_providers.polynomial_weight_function.PolynomialWeightFunction[source]

Bases: pypint.integrators.weight_function_providers.i_weight_function.IWeightFunction

Provider for polynomial weight functions.

Computes weights of given nodes based on a polynomial weight function of the form \(\sum_{i=0}^\infty c_i x^i\). By default, all powers have a coefficient of zero.

Examples

>>> import numpy
>>> nodes = numpy.array([-1.0, 0.0, 1.0])
>>> # To compute the integration weights for a given set of nodes based
>>> # on the constant weight function 1.0 use:
>>> # create an instance
>>> polyWeights = PolynomialWeightFunction()
>>> # set the coefficients of the polynom
>>> polyWeights.init([1.0])
>>> # compute the weights
>>> polyWeights.evaluate(nodes)
>>> # access the weights
>>> polyWeights.weights
array([ 0.3333,  1.3333,  0.3333])
add_coefficient(coefficient, power)[source]

Adds or sets the coefficient \(c\) of \(cx^p\) for a specific \(p\).

The polynomial gets automatically extended to hold the new coefficient in case it didn’t included the specified power previously. Unset, but skipped powers have a coefficient of zero by default.

Parameters:
  • coefficient (float) – Coefficient \(c\) of \(cx^p\).
  • power (int) – Power \(p\) of \(cx^p\).

Examples

>>> polyWeights = PolynomialWeightFunction()
>>> # To set the coefficient of x^3 to 3.14 use:
>>> polyWeights.add_coefficient(3.14, 3)
>>> # Similar, to set the constant coefficient 42, e.i. 42*x^0, use:
>>> polyWeights.add_coefficient(42, 0)
evaluate(nodes, interval=None)[source]

Computes weights for stored polynomial and given nodes.

The weights are calculated with help of the Lagrange polynomials

\[\alpha_i = \int_a^b\omega (x) \prod_{j=1,j \neq i}^{n} \frac{x-x_j}{x_i-x_j} \mathrm{d}x\]

See also

IWeightFunction.evaluate() : overridden method

init(coeffs=[1.0], func=None)[source]

Sets and defines the weights function.

Parameters:
  • coeffs (numpy.ndarray or list) – Array of coefficients of the polynomial.
  • func (str) – Of format c0 + c1 x^1 + c2 x^2... String representation of the polynomial.

Notes

Parsing of a string representation of the polynomial is not yet implemented. Usage will lead to a NotImplementedError exception.

coefficients[source]

Accessor for the polynomial’s coefficients.

To add or alter single coefficients, see add_coefficient().

Parameters:coefficients (numpy.ndarray) – Coefficients of the polynomial.
Returns:coefficients – Coefficients \(c_i\) of the polynomial \(\sum_{i=0}^\infty c_i x^i\).
Return type:numpy.ndarray
Raises:ValueError – If coefficients is not a numpy.ndarray (only Setter).