WallGo.polynomial.Polynomial
- class Polynomial(coefficients, grid, basis='Cardinal', direction='z', endpoints=False)[source]
Bases:
objectClass that stores and perfoms operations on the coefficients of a polynomial series.
Initialization of Polynomial object.
- Parameters:
coefficients (array-like) – Array of rank N containing the coefficients of a polynomial defined by the object grid.
grid (Grid) – An object of the Grid class defining the polynomial.
basis (string or tuple of strings, optional) – Tuple of length N specifying in what basis each dimension of coefficients is defined. Each component can either be ‘Cardinal’, ‘Chebyshev’ or ‘Array’. The latter is to be used if the axis does not corresponds to a polynomial series. Can also be a single string, in which case all the dimensions are assumed to be in that basis. The default is ‘Cardinal’.
direction (string or tuple of strings, optional) – Tuple of length N specifying what direction each dimension of coefficients represents. Each component can either be ‘z’, ‘pz’, ‘pp’ or ‘Array’. The latter can only be used if basis is ‘Array’ for that axis. Can also be a single string, in which case all the dimensions are assumed to be in that direction. The default is ‘z’.
endpoints (bool or tuple of bool, optional) – Tuple of length N specifying wheither each dimension includes the endpoints. Can also be a single bool, in which case all the dimensions are assumed to be the same. If False, the polynomial is assumed to be 0 at the endpoints. The default is False.
- Return type:
None.
- __init__(coefficients, grid, basis='Cardinal', direction='z', endpoints=False)[source]
Initialization of Polynomial object.
- Parameters:
coefficients (array-like) – Array of rank N containing the coefficients of a polynomial defined by the object grid.
grid (Grid) – An object of the Grid class defining the polynomial.
basis (string or tuple of strings, optional) – Tuple of length N specifying in what basis each dimension of coefficients is defined. Each component can either be ‘Cardinal’, ‘Chebyshev’ or ‘Array’. The latter is to be used if the axis does not corresponds to a polynomial series. Can also be a single string, in which case all the dimensions are assumed to be in that basis. The default is ‘Cardinal’.
direction (string or tuple of strings, optional) – Tuple of length N specifying what direction each dimension of coefficients represents. Each component can either be ‘z’, ‘pz’, ‘pp’ or ‘Array’. The latter can only be used if basis is ‘Array’ for that axis. Can also be a single string, in which case all the dimensions are assumed to be in that direction. The default is ‘z’.
endpoints (bool or tuple of bool, optional) – Tuple of length N specifying wheither each dimension includes the endpoints. Can also be a single bool, in which case all the dimensions are assumed to be the same. If False, the polynomial is assumed to be 0 at the endpoints. The default is False.
- Return type:
None.
Methods
__init__(coefficients, grid[, basis, ...])Initialization of Polynomial object.
cardinal(compactCoord, n, direction)Computes the cardinal polynomials \(C_n(x)\) defined by grid.
changeBasis(newBasis[, inverseTranspose])Change the basis of the polynomial.
chebyshev(compactCoord, n[, restriction])Computes the Chebyshev polynomial \(T_n(x)\).
derivMatrix(basis, direction[, endpoints])Computes the derivative matrix of either the Chebyshev or cardinal polynomials in some direction.
derivative(axis)Computes the derivative of the polynomial and returns it in a Polynomial object.
evaluate(compactCoord[, axes])Evaluates the polynomial at the compact coordinates x.
integrate([axis, weight])Computes the integral of the polynomial \(\int_{-1}^1 dx P(x)w(x)\) along some axis using Gauss-Chebyshev-Lobatto quadrature.
matrix(basis, direction[, endpoints])Returns the matrix \(M_{ij}=T_j(x_i)\) or \(M_{ij}=C_j(x_i)\) computed in a specific direction.
Attributes
ALLOWED_BASESALLOWED_DIRECTIONS- cardinal(compactCoord, n, direction)[source]
Computes the cardinal polynomials \(C_n(x)\) defined by grid.
- Parameters:
compactCoord (array_like) – Compact coordinate at which to evaluate the Chebyshev polynomial. Must be broadcastable with n.
n (array_like) – Order of the cardinal polynomial to evaluate. Must be broadcastable with x.
direction (string) – Select the direction in which to compute the matrix. Can either be ‘z’, ‘pz’ or ‘pp’.
- Returns:
cn – Values of the cardinal functions.
- Return type:
array_like
- changeBasis(newBasis, inverseTranspose=False)[source]
Change the basis of the polynomial. Will change self.coefficients accordingly.
- Parameters:
newBasis (string or tuple of strings, optional) – Tuple of length N specifying in what basis each dimension of self.coefficients is defined. Each component can either be ‘Cardinal’ or ‘Chebyshev’. Can also be a single string, in which case all the dimensions are assumed to be in that basis.
inverseTranspose (bool, optional) – If True, take the inverse-transpose of the transformation matrix. This is useful, for example, when changing the basis of the collision array.
- Return type:
None.
- chebyshev(compactCoord, n, restriction=None)[source]
Computes the Chebyshev polynomial \(T_n(x)\).
- Parameters:
compactCoord (array_like) – Compact coordinate at which to evaluate the Chebyshev polynomial. Must be broadcastable with n.
n (array_like) – Order of the Chebyshev polynomial to evaluate. Must be broadcastable with x.
restriction (None or string, optional) – Select the restriction on the Chebyshev basis. If None, evaluates the unrestricted basis. If ‘full’, the polynomials are 0 at \(x=\pm 1\). If ‘partial’, the polynomials are 0 at \(x=+1\).
- Returns:
chen – Values of the polynomial
- Return type:
array_like
- derivMatrix(basis, direction, endpoints=False)[source]
Computes the derivative matrix of either the Chebyshev or cardinal polynomials in some direction.
- Parameters:
basis (string) – Select the basis of polynomials. Can be ‘Cardinal’ or ‘Chebyshev’
direction (string) – Select the direction in which to compute the matrix. Can be ‘z’, ‘pz’ or ‘pp’.
endpoints (Bool, optional) – If True, include endpoints of grid. Default is False.
- Returns:
deriv – Derivative matrix.
- Return type:
array_like
- derivative(axis)[source]
Computes the derivative of the polynomial and returns it in a Polynomial object.
- Parameters:
axis (int or tuple) – axis along which the derivative is taken. Can either be a int or a tuple of int.
- Returns:
Object of the class Polynomial containing the coefficients of the derivative polynomial (in the compact coordinates). The axis along which the derivative is taken is always returned with the endpoints in the cardinal basis.
- Return type:
- evaluate(compactCoord, axes=None)[source]
Evaluates the polynomial at the compact coordinates x.
- Parameters:
compactCoord (array-like) – Compact coordinates at which to evaluate the polynomial. Must have a shape (len(axes),:) or (len(axes),).
axes (tuple or None, optional) – Axes along which to be evaluated. If None, evaluate the polynomial along all the axes. Default is None.
- Returns:
Values of the polynomial at x.
- Return type:
array-like
- integrate(axis=None, weight=1)[source]
Computes the integral of the polynomial \(\int_{-1}^1 dx P(x)w(x)\) along some axis using Gauss-Chebyshev-Lobatto quadrature.
- Parameters:
axis (None, int or tuple) – axis along which the integral is taken. Can either be None, a int or a tuple of int. If None, integrate along all the axes.
weight (array-like, optional) – Integration weight. Must be an object broadcastable with self.coefficients. Default is 1.
- Returns:
If axis=None, returns a float. Otherwise, returns an object of the class Polynomial containing the coefficients of the integrated polynomial along the remaining axes.
- Return type:
Polynomial or float
- matrix(basis, direction, endpoints=False)[source]
Returns the matrix \(M_{ij}=T_j(x_i)\) or \(M_{ij}=C_j(x_i)\) computed in a specific direction.
- Parameters:
basis (string) – Select the basis of polynomials. Can be ‘Cardinal’ or ‘Chebyshev’
direction (string) – Select the direction in which to compute the matrix. Can either be ‘z’, ‘pz’ or ‘pp’
endpoints (Bool, optional) – If True, include endpoints of grid. Default is False.
- Return type:
ndarray